Skip to content

otelhttp: Deprecate WithMetricAttributesFn in favor of Labeler#8587

Merged
pellared merged 6 commits intoopen-telemetry:mainfrom
sonalgaud12:labeler
Mar 2, 2026
Merged

otelhttp: Deprecate WithMetricAttributesFn in favor of Labeler#8587
pellared merged 6 commits intoopen-telemetry:mainfrom
sonalgaud12:labeler

Conversation

@sonalgaud12
Copy link
Copy Markdown
Contributor

@sonalgaud12 sonalgaud12 commented Feb 22, 2026

Addresses #8402
Related: #8107

@sonalgaud12 sonalgaud12 requested review from a team and dmathieu as code owners February 22, 2026 09:16
Comment thread instrumentation/net/http/otelhttp/config.go Outdated
Comment thread CHANGELOG.md Outdated
@pellared pellared merged commit 8096a3e into open-telemetry:main Mar 2, 2026
35 of 36 checks passed
@pellared
Copy link
Copy Markdown
Member

pellared commented Mar 2, 2026

@sonalgaud12, thank you!

@camsteffen
Copy link
Copy Markdown

Just bumped into this. A quick migration guide would be nice. I'm trying to figure it out...

@sonalgaud12 sonalgaud12 deleted the labeler branch March 12, 2026 17:15
emcfarlane pushed a commit to connectrpc/otelconnect-go that referenced this pull request Mar 18, 2026
Add a `Labeler` type, a context-bound, mutex-protected attribute
accumulator that handlers can use to attach custom metric attributes
during request processing. Accessed via `LabelerFromContext` and
`ContextWithLabeler`.

This follows the same pattern as `otelhttp.Labeler` in the upstream
OpenTelemetry contrib library, which deprecated `WithMetricAttributesFn`
in favor of `Labeler` (open-telemetry/opentelemetry-go-contrib#8587).
This implementation aligns with that decision and only adds the `Labeler`
API.

Attributes are added only to metrics, not to spans, since metric
attributes directly affect time series cardinality and must be controlled
independently from trace span attributes. Works for unary and streaming
RPCs on both client and server. The interceptor injects a `Labeler` into
the context automatically if one is not already present. Avoids
allocations on the unary fast path when no custom attributes are set.
Backward-compatible and additive, no existing APIs are modified.

Motivation: standard RPC metrics (e.g. `rpc.server.duration`) already
capture the right measurements but provide no way to attach custom
dimensions (e.g. `product.variant`). `Labeler` solves this cleanly,
matching the approach `otelhttp` uses for HTTP instrumentation.

Closes #199.

---------

Signed-off-by: Michal Jurecko <michal.jurecko@gmail.com>
@sonalgaud12 sonalgaud12 mentioned this pull request Apr 16, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants