Skip to content

Conversation

@dashpole
Copy link
Contributor

@dashpole dashpole commented Jan 12, 2026

Fixes #4126

For open-telemetry/opentelemetry-go#7743.

Changes

Allow binding attributes to an instrument prior to measurement calls. This is useful for performance and ergonomics of the metrics API. For Go, it allows users to do:

counter.WithAttributes(attribute.String("foo", "bar")).Add(ctx, 1)

Instead of (very poor performance):

counter.Add(ctx, 1, WithAttributes(attribute.String("foo", "bar")))

Or, instead of the ugly, performant version.

I'm working on a prototype in Go.

  • Related issues #
  • Related OTEP(s) #
  • Links to the prototypes (when adding or changing features)
  • CHANGELOG.md file updated for non-trivial changes
    • For trivial changes, include [chore] in the PR title to skip the changelog check
  • Spec compliance matrix updated if necessary

@dashpole dashpole force-pushed the bound_instruments branch 2 times, most recently from 6aa45de to 007feae Compare January 12, 2026 16:46
@dashpole
Copy link
Contributor Author

I'm still in discussions with the other Go maintainers about whether we would implement this API if it was added to the spec. I'm planning to leave this as a draft until that point. If other language SIGs are interested in pushing this forward, feel free to write prototypes, and I'll mark it as ready for review after that point.

One thing that came up during discussion is that this differs from how attributes are provided for logs and spans. It is an open question whether this pattern would make sense for logs or spans. I haven't had time to investigate this yet.

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.

Add support for bound instruments to the metrics API

1 participant