Skip to content

Add experimental OptIn instrument advice and View enabled configuration - #8979

Open
dashpole wants to merge 5 commits into
open-telemetry:mainfrom
dashpole:feat/metrics-opt-in-and-view-enabled
Open

dashpole wants to merge 5 commits into
open-telemetry:mainfrom
dashpole:feat/metrics-opt-in-and-view-enabled

Conversation

@dashpole

Copy link
Copy Markdown
Contributor

Summary

Implements the experimental OptIn instrument advisory parameter and View enabled stream configuration defined in open-telemetry/opentelemetry-specification#4809:

  • Incubating Metrics API (opentelemetry-api-incubator):
    • Adds setOptInAdvice(boolean) (default no-op) to all 8 Extended*Builder interfaces (ExtendedDoubleCounterBuilder, ExtendedDoubleGaugeBuilder, ExtendedDoubleHistogramBuilder, ExtendedDoubleUpDownCounterBuilder, ExtendedLongCounterBuilder, ExtendedLongGaugeBuilder, ExtendedLongHistogramBuilder, ExtendedLongUpDownCounterBuilder).
  • Metrics SDK (opentelemetry-sdk-metrics):
    • Adds isOptIn() / setOptIn(boolean) to internal Advice / AdviceBuilder and wires setOptInAdvice(boolean) across all ExtendedSdk*Builder implementations (preserving optIn across .ofDoubles() / .ofLongs() builder swaps).
    • Adds package-private ViewBuilder#setEnabled(boolean) and View#getEnabled(), exposed experimentally via SdkMeterProviderUtil#setEnabled(ViewBuilder, boolean).
    • Updates ViewRegistry#findViews so that:
      • Instruments with OptIn=true use Aggregation.drop() by default when no view matches or when a matching view does not set enabled=true.
      • Matching views with enabled=false use Aggregation.drop() regardless of the view's configured aggregation.
      • Matching views with enabled=true enable OptIn=true instruments while still respecting other instrument advisory parameters (Attributes and ExplicitBucketBoundaries) unless overridden by the view.

@dashpole
dashpole requested a balanced review from Copilot October 27, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-19 22:26 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.77108% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.46%. Comparing base (f67bf22) to head (a40dbba).

Files with missing lines Patch % Lines
...emetry/sdk/metrics/internal/view/ViewRegistry.java 89.74% 2 Missing and 2 partials ⚠️
...try/sdk/metrics/internal/SdkMeterProviderUtil.java 71.42% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8979      +/-   ##
============================================
+ Coverage     90.45%   90.46%   +0.01%     
- Complexity    11181    11206      +25     
============================================
  Files          1032     1032              
  Lines         30507    30581      +74     
  Branches       3992     4002      +10     
============================================
+ Hits          27595    27666      +71     
- Misses         1935     1939       +4     
+ Partials        977      976       -1     

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the localized API additions, SDK enablement logic, or associated regression coverage.

No open issues 🎉

Review effort: Balanced

@psx95 psx95 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.

When registering the associated storage for metrics in SdkMeter, if a view has drop aggregation, then the storage for that is skipped. This could probably cause an issue in the intended functionality because opentelemetry-java evaluates each matching RegisteredView independently in SdkMeter and simply skips (continue) any view whose aggregation is Aggregation.drop(), registering both:

  1. InstrumentSelector("*") → enabled = true
  2. InstrumentSelector("my.unwanted.instrument") → enabled = false and this will not disable "my.unwanted.instrument" since the second view turns into Aggregation.drop() and is skipped by SdkMeter, while the first view (*) still registers a live MetricStorage for "my.unwanted.instrument".

IIUC, this is a key use-case of the spec, right?

@dashpole
dashpole force-pushed the feat/metrics-opt-in-and-view-enabled branch from 7bbc2e1 to e942aa3 Compare October 28, 2026 20:17

@dashpole dashpole left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When registering the associated storage for metrics in SdkMeter, if a view has drop aggregation, then the storage for that is skipped... IIUC, this is a key use-case of the spec, right?

In the Metrics SDK specification (Measurement processing), that difference comes down to view_matching_mode:

  1. In view_matching_mode: independent (the default, and what opentelemetry-java currently implements), each matching View is evaluated independently without merging across views—so just as registering InstrumentSelector("*") (with DefaultAggregation) alongside InstrumentSelector("my.unwanted.instrument") with Aggregation.drop() still exports "my.unwanted.instrument" from the first wildcard view today, enabled only controls the stream produced by that view. (In independent mode, you can disable all instruments by default with InstrumentSelector("*") -> enabled = false and selectively enable InstrumentSelector("my.wanted.instrument") -> enabled = true.)
  2. Overriding InstrumentSelector("*") -> enabled = true with a subsequent InstrumentSelector("my.unwanted.instrument") -> enabled = false is supported under view_matching_mode: composable (open-telemetry/opentelemetry-specification#5173), which merges matching views with the same stream name in registration order using last-wins precedence for enabled, aggregation, description, and aggregation_cardinality_limit.

@dashpole
dashpole marked this pull request as ready for review October 28, 2026 20:17
@dashpole
dashpole requested a review from a team as a code owner October 28, 2026 20:17
@dashpole
dashpole force-pushed the feat/metrics-opt-in-and-view-enabled branch from e942aa3 to 1eb12d5 Compare November 3, 2026 15:12
@opentelemetry-pr-dashboard

This comment has been minimized.

@dashpole

dashpole commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/dashboard route:reviewers

@dashpole
dashpole requested a review from psx95 November 5, 2026 03:26
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@dashpole, this pull request was routed to reviewers. The handoff remains active across pushes until newer actionable human feedback arrives. Top-level feedback through this request will not return; unresolved review threads remain open.

@dashpole
dashpole force-pushed the feat/metrics-opt-in-and-view-enabled branch from 1eb12d5 to a40dbba Compare November 19, 2026 20:18

This branch has not been deployed

No deployments
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.

3 participants