otelhttp: Deprecate WithMetricAttributesFn in favor of Labeler#8587
Merged
pellared merged 6 commits intoopen-telemetry:mainfrom Mar 2, 2026
Merged
otelhttp: Deprecate WithMetricAttributesFn in favor of Labeler#8587pellared merged 6 commits intoopen-telemetry:mainfrom
pellared merged 6 commits intoopen-telemetry:mainfrom
Conversation
pellared
approved these changes
Feb 27, 2026
dmathieu
approved these changes
Mar 2, 2026
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Member
|
@sonalgaud12, thank you! |
|
Just bumped into this. A quick migration guide would be nice. I'm trying to figure it out... |
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>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #8402
Related: #8107