Skip to content

[METRICS] Enable synchronous gauge delta temporality and add tests for multi reader path#4159

Merged
marcalff merged 8 commits into
open-telemetry:mainfrom
niqiangpro-cell:feat/add-support-sync-gauge-with-delta
Jun 19, 2026
Merged

[METRICS] Enable synchronous gauge delta temporality and add tests for multi reader path#4159
marcalff merged 8 commits into
open-telemetry:mainfrom
niqiangpro-cell:feat/add-support-sync-gauge-with-delta

Conversation

@niqiangpro-cell

@niqiangpro-cell niqiangpro-cell commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #4146

Changes

Delta temporality for synchronous gauge instruments was previously unsupported and silently fell back to cumulative. This PR removes that restriction and verifies correct behaviour on the multi-reader slow path (unreported_metrics_).

  • metric_collector.cc
    Removed the guard that rejected kDelta for InstrumentType::kGauge and force-overrode it to kCumulative. Delta temporality for synchronous gauge is now fully supported.

  • temporal_metric_storage.cc
    Clarified the fast-path comment: it applies to all instrument types (not just counter/updown-counter/histogram), and documents the window-scoped last-value semantics for synchronous gauge — only values recorded since the previous collection are emitted; stale values are not re-exported.

  • sync_metric_storage_gauge_test.cc

    • Added WritableMetricStorageDeltaMultiReaderTestFixture, a dedicated fixture for multi-reader delta tests (prevents cross-instantiation with the existing cumulative fixture).
    • Added LongGaugeLastValueAggregationDeltaTemporalityMultiReader(parameterized, int64_t).
    • Added DoubleGaugeLastValueAggregationDeltaTemporalityMultiReader(parameterized, double).

Both new tests exercise the slow path (collectors.size() > 1) and verify:

  1. Each collector independently tracks its own measurement intervals.
  2. First interval start_ts equals instrument creation time (spec [Delta temporality uses MeterProvider start time instead of per-instrument creation time for first collection interval #4062]).
  3. Subsequent start_ts advances to the previous end_ts.
  4. Empty intervals (recordcollectno recordcollect) do not invoke the callback — stale gauge values are not re-emitted, for both collector_a and collector_b independently.
  5. A late-joining collector (collector_b) receives the merged last-value from all prior intervals with start_ts = instrument creation time.

@niqiangpro-cell niqiangpro-cell requested a review from a team as a code owner June 15, 2026 11:58
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 15, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: niqiangpro-cell / name: Elainen6 (1244ff6)
  • ✅ login: niqiangpro-cell / name: niqiangpro-cell (67060a9)

@niqiangpro-cell niqiangpro-cell marked this pull request as draft June 15, 2026 11:58
@niqiangpro-cell niqiangpro-cell marked this pull request as ready for review June 15, 2026 12:08
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.86%. Comparing base (e8c5f43) to head (a322a7b).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4159      +/-   ##
==========================================
+ Coverage   82.82%   82.86%   +0.04%     
==========================================
  Files         406      406              
  Lines       16913    16912       -1     
==========================================
+ Hits        14007    14012       +5     
+ Misses       2906     2900       -6     
Files with missing lines Coverage Δ
sdk/src/metrics/state/metric_collector.cc 96.67% <ø> (+3.02%) ⬆️
sdk/src/metrics/state/temporal_metric_storage.cc 100.00% <100.00%> (+2.23%) ⬆️

... and 1 file with indirect coverage changes

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

Comment thread sdk/test/metrics/sync_metric_storage_gauge_test.cc

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

LGTM, with nit comment. Also the PR title should be updated because this PR is not only adding tests. It also enables sync gauge delta temporality by removing the fallback to cumulative.

@niqiangpro-cell niqiangpro-cell changed the title [METRICS] Add tests for synchrnous gauge with delta temporality in multi reader path [METRICS] Enable synchronous gauge delta temporality and add tests for multi reader path Jun 17, 2026
@niqiangpro-cell

Copy link
Copy Markdown
Contributor Author

Hi, @marcalff @ThomsonTan When you have a moment, could you please review this PR?
I believe it's ready, but happy to make any changes if needed.
Thanks a lot for your time!

@niqiangpro-cell

Copy link
Copy Markdown
Contributor Author

LGTM, with nit comment. Also the PR title should be updated because this PR is not only adding tests. It also enables sync gauge delta temporality by removing the fallback to cumulative.

Thank you for your review. Do you know if this change could make it into the next release cycle?

@marcalff marcalff merged commit 453cfb7 into open-telemetry:main Jun 19, 2026
71 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.

Support synchronous gauge instrument with delta aggregation temporality in C++ SDK

3 participants