Skip to content

New APIs to add/remove metric readers at run-time#4863

Open
JP-MY wants to merge 1 commit intoopen-telemetry:mainfrom
JP-MY:main
Open

New APIs to add/remove metric readers at run-time#4863
JP-MY wants to merge 1 commit intoopen-telemetry:mainfrom
JP-MY:main

Conversation

@JP-MY
Copy link
Copy Markdown

@JP-MY JP-MY commented Dec 18, 2025

Description

This change adds two public functions to MeterProvider that allow registering and deleting metric readers at run-time.

Fixes #4818

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • It has been tested via new unit test added to ensure correct behavior for addition and removal of metric readers at run-time.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

@JP-MY JP-MY requested a review from a team as a code owner December 18, 2025 14:20
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Dec 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: JP-MY / name: Mani Yazdankhah (8c6e48d)

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Copy link
Copy Markdown
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, sorry for the delay here.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
@JP-MY JP-MY force-pushed the main branch 2 times, most recently from ef20f0e to 9bb1567 Compare February 13, 2026 07:58
@JP-MY
Copy link
Copy Markdown
Author

JP-MY commented Feb 14, 2026

@aabmass @herin049 I'm not sure why the lint is failing for protected access, I can see the same protected access in the same file. Should I add a pylint: disable= rule or is there a config for this that I need to update? also the contrib test fails don't seem related (failed to get a specific commit?) but I'm not sure if I messed something up to cause that or not.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Copy link
Copy Markdown
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the concurrency issues, LGTM!

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py Outdated
Comment thread opentelemetry-sdk/tests/metrics/test_metrics.py
Comment thread opentelemetry-sdk/tests/metrics/test_metrics.py
)
return self._meters[info]

def add_metric_reader(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@xrmx Any concerns on new public API here?

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.

Can we start with private methods and see if the declarative config work has any interaction with this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not familiar with the declerative config work but we need this API accessible at run time (after initial configuration). Would that be supported by the decelartive config work?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't get the point either @xrmx

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have addressed all other comments, if we are ok with the public API can we proceed with merging this?

@tammy-baylis-swi tammy-baylis-swi moved this to Reviewed PRs that need fixes in Python PR digest Feb 26, 2026
@tammy-baylis-swi tammy-baylis-swi moved this from Reviewed PRs that need fixes to Approved PRs that need fixes in Python PR digest Feb 26, 2026
@JP-MY JP-MY force-pushed the main branch 3 times, most recently from 8a5c6ef to 04a652a Compare March 21, 2026 12:55
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/__init__.py Outdated
)
return self._meters[info]

def add_metric_reader(
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.

Can we start with private methods and see if the declarative config work has any interaction with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Exposing public APIs to for addition and removal of metric readers at run-time

5 participants