Skip to content

[SDK] refactor: exemplar filters - #4267

Merged
dbarker merged 36 commits into
open-telemetry:mainfrom
proost:feat-exemplar-filters
Aug 12, 2026
Merged

[SDK] refactor: exemplar filters#4267
dbarker merged 36 commits into
open-telemetry:mainfrom
proost:feat-exemplar-filters

Conversation

@proost

@proost proost commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Related to #4178, #2526

Changes

Breaking Change is accompanied, But Because this is preview version, I think acceptable.

I will send another PR for configuration from envs.

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@proost
proost requested a review from a team as a code owner July 18, 2026 05:50
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.65%. Comparing base (3893576) to head (0e5c5de).

Files with missing lines Patch % Lines
...ntelemetry/sdk/metrics/state/sync_metric_storage.h 55.56% 4 Missing ⚠️
...entelemetry/sdk/metrics/exemplar/reservoir_utils.h 75.00% 1 Missing ⚠️
...telemetry/sdk/metrics/state/async_metric_storage.h 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4267      +/-   ##
==========================================
+ Coverage   82.49%   82.65%   +0.16%     
==========================================
  Files         502      503       +1     
  Lines       19899    19904       +5     
==========================================
+ Hits        16414    16449      +35     
+ Misses       3485     3455      -30     
Files with missing lines Coverage Δ
...ude/opentelemetry/sdk/metrics/data/exemplar_data.h 100.00% <100.00%> (+100.00%) ⬆️
...ntelemetry/sdk/metrics/exemplar/filter_predicate.h 100.00% <100.00%> (ø)
...k/metrics/exemplar/fixed_size_exemplar_reservoir.h 89.66% <100.00%> (ø)
...metry/sdk/metrics/exemplar/no_exemplar_reservoir.h 100.00% <100.00%> (ø)
...ude/opentelemetry/sdk/metrics/exemplar/reservoir.h 100.00% <ø> (ø)
...pentelemetry/sdk/metrics/exemplar/reservoir_cell.h 97.83% <100.00%> (+41.31%) ⬆️
sdk/src/metrics/meter.cc 81.36% <ø> (ø)
...entelemetry/sdk/metrics/exemplar/reservoir_utils.h 95.24% <75.00%> (-4.76%) ⬇️
...telemetry/sdk/metrics/state/async_metric_storage.h 93.19% <75.00%> (+2.28%) ⬆️
...ntelemetry/sdk/metrics/state/sync_metric_storage.h 84.94% <55.56%> (+1.19%) ⬆️

... and 2 files with indirect coverage changes

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

@lalitb

lalitb commented Jul 20, 2026

Copy link
Copy Markdown
Member

@proost - I think this won't yet close #4178 - We can't declare exemplar stable till we have evaluated their performance on hot-path of metrics.

Comment thread sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_utils.h Outdated
Comment thread sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h Outdated
@proost
proost requested a review from lalitb July 22, 2026 15:05
Comment thread sdk/test/metrics/exemplar/filtered_exemplar_reservoir_test.cc Outdated
@proost
proost requested a review from dbarker July 25, 2026 04:14

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

Thanks for the PR! Please see some initial feedback below.

Comment thread sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h Outdated
Comment thread sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h Outdated
Comment thread sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h Outdated
@proost proost changed the title [SDK] feat: exemplar filters [SDK] fix: exemplar filters Jul 31, 2026
@proost

proost commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@dbarker @lalitb
I'm sorry to bothering you. I missunderstand the issue and spec.

So this PR change:

  1. removing span context check so that alwaysOn works correctly.
  2. little bit refactoring(removing useless "GetSimpleFilteredExemplarReservoir")
  3. tiny performance improving that removing timestamp.

@proost
proost requested a review from dbarker July 31, 2026 14:31
Comment thread CHANGELOG.md

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.

🟡 Not ready to approve

There are correctness and robustness issues in the updated exemplar code paths (notably async exemplar attribute handling and reservoir cell reset semantics) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR updates the Metrics SDK exemplar “preview” pipeline to align with spec changes by moving exemplar eligibility logic into a predicate, simplifying reservoir selection based on the filter type, and removing timestamps from the ExemplarReservoir::OfferMeasurement() API.

Changes:

  • Remove the SystemTimestamp parameter from preview ExemplarReservoir::OfferMeasurement() and update all call sites/tests accordingly.
  • Centralize exemplar eligibility via ExemplarFilterEnabled(...) and add unit tests for the filter predicate and span-context behavior.
  • Adjust exemplar reservoir construction to respect ExemplarFilterType (notably kAlwaysOff) and update build/test wiring (CMake + Bazel).
File summaries
File Description
sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc Removes legacy tests tied to the old ExemplarFilter interface.
sdk/test/metrics/exemplar/always_sample_filter_test.cc Removes legacy tests tied to the old ExemplarFilter interface.
sdk/test/metrics/exemplar/reservoir_cell_test.cc Adds coverage for producing exemplars without an active span context.
sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc Updates tests for the new OfferMeasurement signature (no timestamp).
sdk/test/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir_test.cc Updates tests for the new OfferMeasurement signature (no timestamp).
sdk/test/metrics/exemplar/filter_predicate_test.cc Adds new unit tests for ExemplarFilterEnabled(...) behavior.
sdk/test/metrics/exemplar/CMakeLists.txt Registers the new filter predicate test target.
sdk/test/metrics/exemplar/BUILD Registers the new Bazel test target for filter predicate tests.
sdk/src/metrics/meter.cc Passes the filter type into reservoir selection.
sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h Uses ExemplarFilterEnabled and removes timestamp from reservoir offers.
sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h Uses ExemplarFilterEnabled and removes timestamp from reservoir offers.
sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h Updates the reservoir interface to drop timestamps and removes filtered-reservoir factory.
sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_utils.h Selects NoExemplarReservoir when filter is kAlwaysOff and uses factory helpers.
sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h Changes how span context is captured (always overwritten).
sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h Updates overrides for the new OfferMeasurement signature.
sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h Updates overrides for the new OfferMeasurement signature.
sdk/include/opentelemetry/sdk/metrics/exemplar/filter_predicate.h Introduces the shared exemplar filter predicate helper.
ci/do_ci.sh Increases Bazel valgrind test timeout.
CHANGELOG.md Documents exemplar filtering changes and the breaking preview API update.
Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 5
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread sdk/test/metrics/exemplar/reservoir_cell_test.cc
Comment thread sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h
Comment thread sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h
Comment on lines +30 to +40
switch (filter_type)
{
case ExemplarFilterType::kAlwaysOn:
return true;
case ExemplarFilterType::kAlwaysOff:
return false;
default: // TraceBased.
const opentelemetry::trace::SpanContext span_context =
opentelemetry::trace::GetSpanContext(context);
return span_context.IsValid() && span_context.IsSampled();
}
Comment thread CHANGELOG.md

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

Thanks for the fix. I think this is reasonable. Please see optional feedback (can be follow up PRs) and consider the copilot feedback. We do still need benchmarking for the exemplar path to resolve the linked ticket.

Comment thread sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h Outdated
@lalitb

lalitb commented Aug 11, 2026

Copy link
Copy Markdown
Member

@proost Could you please change Fixes #4178 to Related to #4178 in the PR description? This PR improves the exemplar implementation, but we still need hot-path performance evaluation before considering exemplars stable and closing that issue.

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

Thanks.

@proost proost changed the title [SDK] fix: exemplar filters [SDK] refactor: exemplar filters Aug 11, 2026
@dbarker
dbarker merged commit 19e0244 into open-telemetry:main Aug 12, 2026
73 checks passed
@proost
proost deleted the feat-exemplar-filters branch August 12, 2026 12:13
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.

6 participants