opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
[otelgin] Would extract Baggage from parent span be supported in the roadmap?
Problem Statement
When parent span injects baggage, otelgin seems not parse baggage information. ( https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go#L70 )
Proposed Solution
In https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go, implement baggage.FromContext(ctx)
and set it to it's span attributes.
sample code
ctx := cfg.Propagators.Extract(req.Context(), propagation.HeaderCarrier(req.Header))
ctx, span := tracer.Start(ctx, spanName, opts...)
defer span.End()
reqBaggage := baggage.FromContext(ctx)
span.SetAttributes(
attribute.String("user.id", reqBaggage.Member("user.id").Value()),
attribute.String("user.name", reqBaggage.Member("user.name").Value()),
)
Alternatives
N/A
Prior Art
N/A
Additional Context
N/A
I'm not sure extracting the entire baggage into the span is the correct generic behavior. It seems it would be better to have a custom middleware on your end which would retrieve the span from the context and add the attributes you need.
@dmathieu Thank you for the suggestion for the baggage. I am new to OpenTelemetry, and my understanding is that a Span is immutable and otelgin starts a span already. So my middleware to extra baggage should be prior than otelgin's middleware, otherwise there will be two spans, right? Please correct if I am wrong, thank you.
Spans are only immutable once ended. They can be extended with new attributes and events at any moment, until End() has been called.