How to link to an incoming trace context #518
-
When using the otel_propagator extract functions, the current trace is switched to the span context of the incoming request. Any further spans then become children of that span. What I want is to extract the span context of the incoming request and then only link to that context. I can work around the limit of extract_trace_id(IEs) ->
Ctx = otel_ctx:get_current(),
CurrentSpan = otel_tracer:current_span_ctx(Ctx),
Ctx1 = otel_propagator_trace_context:extract(Ctx, IEs, undefined, fun trace_get/2, #{}),
TraceSpan = otel_tracer:current_span_ctx(Ctx1),
otel_traceqr:set_current_span(Ctx, CurrentSpan),
TraceSpan. The root oy my problem is actually this line: https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_api/src/otel_propagator_trace_context.erl#L97 Why does |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You likely don't want to use But it acts essentially the same in the end. I think your issue is some confusion around how context works and the process dictionary. The code you show can be done like:
If you just want the span ctx from the headers then you can create a new ctx Also, note in your code that |
Beta Was this translation helpful? Give feedback.
You likely don't want to use
otel_propagator_trace_context
directly here. A user is meant to useotel_propagator_text_map
which hasextract_to
: https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_api/src/otel_propagator_text_map.erl#L164But it acts essentially the same in the end.
I think your issue is some confusion around how context works and the process dictionary. The code you show can be done like:
If you just want the span ctx from the headers then you can create a new ctx
otel_ctx:new()
…