Skip to content

Conversation

@cijothomas
Copy link
Member

@cijothomas cijothomas commented Jan 22, 2026

Was initially kept under feature flag to keep scope under control. Stabilizing more and more things now!
Also added additional tests as users can now change Aggregations -

  1. Added ExponentialHistogram to coverage
  2. Added test coverage to validate that we restrict certain aggregations (Counters can be aggregated using LastValue, and Gauges cannot be aggregated as Sum etc.) - There is no real spec behind this, but this is to avoid producing semantically correct aggregation. We could remove this restriction, if there are actual use cases behind them. Don't think it'd be a breaking change.

@cijothomas cijothomas requested a review from a team as a code owner January 22, 2026 03:20
@cijothomas
Copy link
Member Author

@ArniDagur Could you review, since you recently worked in this area!

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 96.79666% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.8%. Comparing base (092983f) to head (5b38106).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/metrics/mod.rs 96.3% 23 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3322     +/-   ##
=======================================
+ Coverage   81.1%   81.8%   +0.7%     
=======================================
  Files        129     129             
  Lines      23719   24366    +647     
=======================================
+ Hits       19238   19938    +700     
+ Misses      4481    4428     -53     

☔ 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.

Copy link
Contributor

Copilot AI left a comment

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 stabilizes more of the metrics Views surface area by making aggregation customization available without the spec_unstable_metrics_views feature flag, and aligns view behavior with the spec by falling back to default aggregation when matching views are incompatible.

Changes:

  • Make Aggregation and StreamBuilder::with_aggregation() usable without spec_unstable_metrics_views.
  • Update view resolution to “proceed as if the View did not match” when all matching views produce incompatible aggregators (with a warning).
  • Add tests covering aggregation overrides via views (including exponential histogram) and incompatible aggregation fallback behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
opentelemetry-sdk/src/metrics/pipeline.rs Adjusts view matching behavior to ignore incompatible views and fall back to default aggregation; adds a warning log.
opentelemetry-sdk/src/metrics/mod.rs Removes feature-gating around aggregation exports and adds multiple tests for view aggregation behavior.
opentelemetry-sdk/src/metrics/internal/histogram.rs Removes feature-gated boundary sanitization logic now that boundaries are validated earlier.
opentelemetry-sdk/src/metrics/instrument.rs Removes feature-gating for with_aggregation() and a related test gate.
opentelemetry-sdk/CHANGELOG.md Documents stabilization of Aggregation and StreamBuilder::with_aggregation().
examples/metrics-advanced/Cargo.toml Updates the example to use stable metrics feature instead of the unstable views feature.

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


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

Comment on lines +309 to +313
// If at least one view matched and produced a valid aggregator, return it.
// If views matched but all failed (e.g., incompatible aggregation), fall through
// to apply the default view per the spec: "proceed as if the View did not [match]".
if matched && !measures.is_empty() {
return Ok(measures);
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

The new early-return condition if matched && !measures.is_empty() breaks Aggregation::Drop views. When a view matches and selects Aggregation::Drop, cached_aggregator returns Ok(None) and the code continues, leaving measures empty and errs empty. This then falls through to the implicit default view and creates a default aggregator, so the instrument is no longer dropped.

Consider treating Ok(None) as a successful view application: only fall back to the default when matched && measures.is_empty() && !errs.is_empty() (i.e., all matching views failed), and otherwise return Ok(measures) even if empty.

Copilot uses AI. Check for mistakes.
Comment on lines +943 to +946
// LastValue aggregation is only valid for Gauge instruments.
// When applied to a Counter via a view, the view is ignored and
// the default aggregation (Sum) is used per the spec:
// "proceed as if the View did not match"
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

PR description says we "restrict certain aggregations (Counters can be aggregated using LastValue...)", but this test (and is_aggregator_compatible) treats LastValue as incompatible for Counter and falls back to Sum. Please update the PR description to match the implemented behavior (or adjust the behavior if the description is the intent).

Copilot uses AI. Check for mistakes.
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.

2 participants