diff --git a/src/api/routes/route.py b/src/api/routes/route.py index aca17582c67be5dcbab636db8576fb44527313ce..4c9e8c1296c73331ada00e2eb7e7cb4345ab99f7 100644 --- a/src/api/routes/route.py +++ b/src/api/routes/route.py @@ -240,13 +240,21 @@ def _handle_api_request( start_time = time.time_ns() if do_tracing: + from opentelemetry.instrumentation.utils import propagator from opentelemetry.sdk.trace import 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, "server": _SERVER_NAME, }): 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: resp = _execute_api_route(call_counter, allow_while_readonly, allow_while_disabled, rate_limiters, func, args, kwargs)