Skip to content

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

Merged
jack-berg merged 7 commits into
open-telemetry:mainfrom
dashpole:feat/metrics-opt-in-and-view-enabled
Nov 25, 2026
Merged

jack-berg merged 7 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

Merged · refreshed 2026-11-25 22:17 UTC

Status above doesn't look right?
  • 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.55%. Comparing base (f67bf22) to head (4350681).
⚠️ Report is 5 commits behind head on main.

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.55%   +0.09%     
- Complexity    11181    11217      +36     
============================================
  Files          1032     1032              
  Lines         30507    30598      +91     
  Branches       3992     4009      +17     
============================================
+ Hits          27595    27707     +112     
+ Misses         1935     1914      -21     
  Partials        977      977              

☔ 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

@jack-berg jack-berg left a comment •

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.

This looks good. Thanks!

I did push two commits, to improve the readability of the OptInAdviceTest, and to add a TODO to potentially reject Views at construction time which specify enabled=false along with an aggregation, since this is not useful to specify.

@jack-berg
jack-berg merged commit 9eb346a into open-telemetry:main Nov 25, 2026
34 checks passed
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.

4 participants