Skip to content

opentelemetry-api: implement metrics bind API#5450

Open
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/instrument-bind
Open

opentelemetry-api: implement metrics bind API#5450
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/instrument-bind

Conversation

@herin049

Copy link
Copy Markdown
Contributor

Description

Implements the OTel metrics Bind API.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

uv run tox -e py314-test-opentelemetry-api

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for “bound” synchronous metric instruments (per the OTel Metrics Bind concept), allowing instruments to be pre-associated with a set of attributes and to merge those attributes with per-call attributes at recording time.

Changes:

  • Adds _bind() to synchronous instrument types and introduces bound-instrument wrappers that delegate recording while merging/deepcopying attributes.
  • Adds API-level tests covering delegation behavior, attribute merging semantics, deepcopy behavior, rebinding flattening, and proxy instrument interaction.
  • Adds SDK-level tests validating that bound recordings flow through the measurement consumer and preserve existing validation behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py Adds _bind() and bound instrument wrapper implementations for synchronous instruments.
opentelemetry-api/tests/metrics/test_instruments.py Adds API tests for bound instrument semantics (merge/deepcopy/rebind/proxy).
opentelemetry-sdk/tests/metrics/test_instrument.py Adds SDK tests to ensure bound instruments propagate measurements/validation correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py
Comment thread opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py
Comment thread opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py
Comment thread opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants