Skip to content

feat: Add and enabled Metric cardinality capping by default #2901

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

Merged

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Apr 4, 2025

Fixes #1065

Re-introduce Metric cardinality capping, but this time, with the ability to configure the limit using Views.
The default is 2000, following OTel spec.
There is no ability to change the limit globally (at reader level) - this is not a MUST from the spec, and based on my experience, this is rarely used/needed.
Existing tests are re-enabled, and also enhanced to test customization ability and to test that limits are per cycle.

TODO (in next PR): is to add coverage for all instruments, as only Counters are currently covered.
TODO : doc additions. Depending on the next PR where I plan to introduce customization ability via Advisory, we can decide how best to document this.
TODO(next PR): Fix #2878 too

I expect to send another PR which will enhance the Instrument Advisory parameters to accept cardinality limits via that option. This is not a thing from the spec (but spec does not prohibit offering additional capabilities either), but planned to be added to Rust as using Views is generally non-trivial and my own experience tells it is somewhat confusing.
(Also planning to make a spec enhancement proposal in parallel, but I don't think it is a blocker)

@cijothomas cijothomas requested a review from a team as a code owner April 4, 2025 17:48
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 97.16599% with 7 lines in your changes missing coverage. Please review.

Project coverage is 81.3%. Comparing base (86e842c) to head (a190bd1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-sdk/src/metrics/mod.rs 95.0% 6 Missing ⚠️
opentelemetry-sdk/src/metrics/pipeline.rs 92.8% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2901     +/-   ##
=======================================
+ Coverage   81.0%   81.3%   +0.2%     
=======================================
  Files        125     125             
  Lines      23945   24132    +187     
=======================================
+ Hits       19414   19628    +214     
+ Misses      4531    4504     -27     

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

let AggregateFns { measure, collect } = match aggregate_fn(b, &agg, kind) {
Ok(Some(inst)) => inst,
other => return other.map(|fs| fs.map(|inst| inst.measure)), // Drop aggregator or error
};

otel_debug!(
name : "Metrics.InstrumentCreated",
instrument_name = stream.name.as_ref(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Add Aggregation information as well to understand what kind of instrument was created.

@cijothomas cijothomas merged commit 2564a71 into open-telemetry:main Apr 4, 2025
24 checks passed
@cijothomas cijothomas deleted the cijothomas/cardinality-cap branch April 4, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants