Skip to content
Snippets Groups Projects
Commit b37a611f authored by Simon Künzel's avatar Simon Künzel
Browse files

Actually extract/inject trace from/into HTTP headers

parent 8a6ac9d0
Branches
Tags v1.0.8
No related merge requests found
Pipeline #7111 passed
...@@ -240,13 +240,21 @@ def _handle_api_request( ...@@ -240,13 +240,21 @@ def _handle_api_request(
start_time = time.time_ns() start_time = time.time_ns()
if do_tracing: if do_tracing:
from opentelemetry.instrumentation.utils import propagator
from opentelemetry.sdk.trace import Tracer from opentelemetry.sdk.trace import Tracer
assert isinstance(open_telemetry_tracer, Tracer) assert isinstance(open_telemetry_tracer, Tracer)
with open_telemetry_tracer.start_as_current_span("api-request", attributes={
context = propagator.extract(request.headers)
with open_telemetry_tracer.start_as_current_span("api-request", context=context, attributes={
"url": request.url, "url": request.url,
"server": _SERVER_NAME, "server": _SERVER_NAME,
}): }):
resp = _execute_api_route(call_counter, allow_while_readonly, allow_while_disabled, rate_limiters, func, args, kwargs) resp = _execute_api_route(call_counter, allow_while_readonly, allow_while_disabled, rate_limiters, func, args, kwargs)
# Note that the context still contains the client's span, and we inject that. Not our span (the HTTP header is
# called "traceparent")
propagator.inject(resp.headers, context=context)
else: else:
resp = _execute_api_route(call_counter, allow_while_readonly, allow_while_disabled, rate_limiters, func, args, kwargs) resp = _execute_api_route(call_counter, allow_while_readonly, allow_while_disabled, rate_limiters, func, args, kwargs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment