[METRICS] Fix stale async attribute sets in cumulative exports (#4108) - #4484
Open
vahle-at-psu wants to merge 1 commit into
Open
[METRICS] Fix stale async attribute sets in cumulative exports (#4108)#4484vahle-at-psu wants to merge 1 commit into
vahle-at-psu wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4484 +/- ##
==========================================
+ Coverage 83.12% 83.13% +0.02%
==========================================
Files 519 519
Lines 20256 20258 +2
==========================================
+ Hits 16835 16839 +4
+ Misses 3421 3419 -2
🚀 New features to boost your workflow:
|
…telemetry#4108) Async instruments (ObservableCounter, ObservableGauge, ObservableUpDownCounter) under cumulative temporality were emitting attribute sets indefinitely after the callback stopped reporting them, violating the OTel spec requirement: "The implementation SHOULD NOT produce aggregated metric data for a previously-observed attribute set which is not observed during a successful callback." Root cause: `TemporalMetricStorage::buildMetrics()` unconditionally carried every entry from `last_reported_metrics_` into the output even when it was absent from the current delta. Fix: - Add `is_async_` flag (default false) to `TemporalMetricStorage`. The cumulative merge now skips entries not present in the current delta for async instruments, while sync instruments retain the existing carry-forward behaviour. - Pass `is_async = true` when constructing `TemporalMetricStorage` from `AsyncMetricStorage`. - Do NOT prune `cumulative_hash_map_` in `AsyncMetricStorage::Collect()` so that the absolute-value baseline is preserved across absent cycles. This ensures correct delta computation (new - last_seen, not the full new value) when an attribute set reappears after a gap — consistent with the approach taken by opentelemetry-dotnet#6883. Tests added in async_metric_storage_test.cc: - StaleAttributeSetDroppedInCumulativeExport: verifies that an attribute set absent from the callback is not emitted in subsequent cumulative exports. - AttributeReappearanceAfterGapDeltaTemporality: verifies that an attribute set reappearing after an absent cycle emits only the increment since last observed (delta = 1, not 11), confirming the baseline is correctly preserved. Fixes open-telemetry#4108 Co-authored-by: pranitaurlam <227409059+pranitaurlam@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4108.
This PR continues the work from #4140 by @pranitaurlam. Since the original author has been unresponsive for several weeks and the fix is needed in production, I am taking over the PR, giving full credit to @pranitaurlam for the original analysis and fix skeleton.
Async instruments (
ObservableCounter,ObservableGauge,ObservableUpDownCounter) under cumulative temporality emitted attribute sets indefinitely after the callback stopped reporting them, violating the OTel spec:Root cause
TemporalMetricStorage::buildMetrics()unconditionally carried every entry fromlast_reported_metrics_into the cumulative output, even when the attribute set was absent from the current delta.Changes
temporal_metric_storage.h/.ccis_async_boolean (defaultfalse) toTemporalMetricStorage.else if (!is_async_)guard: sync instruments still carry forward all attribute sets (existing behaviour, spec-correct); async instruments skip entries not present in the current delta.async_metric_storage.his_async = truewhen constructingTemporalMetricStorage.cumulative_hash_map_inCollect()(deviation from [METRICS] Drop stale async attribute sets from cumulative exports #4140): the absolute-value baseline is preserved across absent cycles. This ensures correct incremental delta computation when an attribute set reappears after a gap (delta = new − last_seen, notnew), consistent with opentelemetry-dotnet#6883. Stale entries are suppressed at export time by theis_async_guard instead.Behaviour
Sister SDKs with equivalent fixes:
Tests
Two regression tests added in
async_metric_storage_test.cc, addressing lalitb's review request on #4140:StaleAttributeSetDroppedInCumulativeExport: attribute present incollection 1, absent in collection 2 → must not appear in collection
2's cumulative export.
AttributeReappearanceAfterGapDeltaTemporality:A=10 → missing → A=11under delta temporality → emitted delta must be1, not11,confirming the baseline is preserved across the absent cycle.
Co-authored-by: pranitaurlam 227409059+pranitaurlam@users.noreply.github.com