Skip to content

manually propagating trace & span #633

Answered by fbogsany
tobert asked this question in Q&A
Discussion options

You must be logged in to vote

You likely want to write your own Getter and Setter and then use the global OpenTelemetry.propagation to extract the context, then use it to start a child span. That's the golden path, but you can hack it...

Your example is breaking because with_parent: expects an OpenTelemetry::Context rather than an OpenTelemetry::Trace::SpanContext. You could "fix" it by wrapping the SpanContext, like:

sc = OpenTelemetry::Trace::SpanContext.new(trace_id: tid, span_id: sid)
parent_span = OpenTelemetry::Trace:Span.new(span_context: sc)
parent = OpenTelemetry::Trace.context_with_span(parent_span)
tracer.start_span("test", with_parent: parent) do |span|
    sleep 0.1
end

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tobert
Comment options

Answer selected by tobert
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ahayworth
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants