0
0
Microservicessystem_design~10 mins

Distributed tracing (Jaeger, Zipkin) in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a new trace span in a microservice.

Microservices
tracer = init_tracer('my-service')
with tracer.start_span('[1]') as span:
    process_request()
Drag options to blanks, or click blank then click option'
Atrace_span
Btrace_id
Cspan_context
Dhandle_request
Attempts:
3 left
💡 Hint
Common Mistakes
Using internal IDs like 'trace_id' instead of a descriptive span name.
Confusing span context with span name.
2fill in blank
medium

Complete the code to propagate trace context via HTTP headers.

Microservices
headers = {}
tracer.inject(span.context, format=[1], carrier=headers)
send_request(headers)
Drag options to blanks, or click blank then click option'
AFormat.HTTP_HEADERS
BFormat.TEXT_MAP
CFormat.JSON
DFormat.BINARY
Attempts:
3 left
💡 Hint
Common Mistakes
Using binary or JSON formats which are not suitable for HTTP headers.
Using TEXT_MAP which is generic but not specific for HTTP headers.
3fill in blank
hard

Fix the error in the code to correctly extract trace context from incoming HTTP headers.

Microservices
span_ctx = tracer.extract(format=[1], carrier=request.headers)
with tracer.start_span('handle', child_of=span_ctx) as span:
    process()
Drag options to blanks, or click blank then click option'
AFormat.TEXT_MAP
BFormat.HTTP_HEADERS
CFormat.BINARY
DFormat.JSON
Attempts:
3 left
💡 Hint
Common Mistakes
Using TEXT_MAP or BINARY formats which cause extraction errors.
Not matching the injection format.
4fill in blank
hard

Fill both blanks to create a trace span with tags for service name and error status.

Microservices
with tracer.start_span('db_query') as span:
    span.set_tag('[1]', 'user-service')
    span.set_tag('[2]', True)
Drag options to blanks, or click blank then click option'
Aservice.name
Berror
Chttp.status_code
Dspan.kind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http.status_code' instead of 'error' for error tagging.
Confusing 'span.kind' with service name.
5fill in blank
hard

Fill all three blanks to create a dictionary of spans with their durations filtered by duration > 100ms.

Microservices
slow_spans = {span.[1]: span.[2] for span in spans if span.[3] > 100}
Drag options to blanks, or click blank then click option'
Aoperation_name
Bduration_ms
Dstart_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start_time' instead of 'duration_ms' for filtering.
Mixing up keys and values in the dictionary comprehension.