Skip to content

fix: Make NoopMeterProvider public to allow external usage #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 3, 2025

This PR restores public access to NoopMeterProvider which was made private in PR #2191. The NoopMeterProvider is useful for applications that want to conditionally disable telemetry at compile time without changing their instrumentation code.

Changes

  • Made the noop module public in opentelemetry/src/metrics/mod.rs
  • Changed NoopMeterProvider struct visibility from pub(crate) to pub
  • Changed NoopMeterProvider::new() method visibility from pub(crate) to pub
  • Added NoopMeterProvider to the public exports in the metrics module

Usage

Users can now directly use NoopMeterProvider for conditional telemetry:

use opentelemetry::metrics::{MeterProvider, NoopMeterProvider};

// Create a no-op meter provider for conditional telemetry
let provider = NoopMeterProvider::new();
let meter = provider.meter("my_app");

// All instruments created from this meter will be no-ops
let counter = meter.u64_counter("requests").build();
counter.add(1, &[]); // This operation is a no-op

This allows applications to use feature flags or environment variables to conditionally disable telemetry without requiring code changes or copying the NoopMeterProvider implementation.

Fixes #2444.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] [Feature]: Make NoopMeterProvider public Make NoopMeterProvider public to allow external usage Aug 3, 2025
Copilot finished work on behalf of cijothomas August 3, 2025 18:49
@Copilot Copilot AI requested a review from cijothomas August 3, 2025 18:49
@cijothomas cijothomas marked this pull request as ready for review August 4, 2025 17:23
@cijothomas cijothomas requested a review from a team as a code owner August 4, 2025 17:23
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.4%. Comparing base (86dfd4b) to head (ba26861).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3111   +/-   ##
=====================================
  Coverage   80.4%   80.4%           
=====================================
  Files        126     126           
  Lines      22237   22237           
=====================================
  Hits       17898   17898           
  Misses      4339    4339           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cijothomas cijothomas changed the title Make NoopMeterProvider public to allow external usage fix: Make NoopMeterProvider public to allow external usage Aug 4, 2025
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.

[Feature]: Make NoopMeterProvider public
3 participants