opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
Labeler support for traced spans
Problem Statement
Using the otelhttp.Labeler is a nice way to get custom attributes into the metrics produced by the instrumentation. When trying to correlate this metric data with other sources, like spans, it would be helpful to have these custom attributes on both the metric and span data.
Proposed Solution
Add the attributes from the labeler to the span after serving. Something like https://github.com/open-telemetry/opentelemetry-go-contrib/compare/main...austince:opentelemetry-go-contrib:feat/support-span-labeler?expand=1
Alternatives
Have a separate SpanLabeler or such. This seemed more complex than valuable.
otelhttp has a WithSpanOptions which allows doing that.
@dmathieu thanks for the link! I see there's a WithAttributes SpanStartEventOption, but that only allows setting statically known attributes. The otelhttp.Labeler allows dynamic attributes that can be attached in other route middleware -- is there a way to do that using WithSpanOptions?