opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

Labeler support for traced spans

Open austince opened this issue 2 years ago • 2 comments

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.

austince avatar Aug 23 '23 20:08 austince

otelhttp has a WithSpanOptions which allows doing that.

dmathieu avatar Aug 24 '23 06:08 dmathieu

@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?

austince avatar Aug 24 '23 14:08 austince