Skip to content

How to link to an incoming trace context #518

Answered by tsloughter
RoadRunnr asked this question in Q&A
Discussion options

You must be logged in to vote

You likely don't want to use otel_propagator_trace_context directly here. A user is meant to use otel_propagator_text_map which has extract_to: https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_api/src/otel_propagator_text_map.erl#L164

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:

extract_trace_id(IEs) ->
    Ctx = otel_propagator_trace_context:extract(otel_ctx:new(), IEs, undefined, fun trace_get/2, #{}),
   otel_tracer:current_span_ctx(Ctx).

If you just want the span ctx from the headers then you can create a new ctx otel_ctx:new()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RoadRunnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants