Skip to content

fix(opentelemetry-sdk): keep synchronous gauge values across cumulative collections - #5637

Merged
aabmass merged 6 commits into
open-telemetry:mainfrom
kacper-wolkiewicz-reef:fix-sync-gauge-cumulative-persistence
Sep 10, 2026
Merged

fix(opentelemetry-sdk): keep synchronous gauge values across cumulative collections#5637
aabmass merged 6 commits into
open-telemetry:mainfrom
kacper-wolkiewicz-reef:fix-sync-gauge-cumulative-persistence

Conversation

@kacper-wolkiewicz-reef

@kacper-wolkiewicz-reef kacper-wolkiewicz-reef commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Description

The MetricReader spec requires that for synchronous instruments with cumulative aggregation temporality, Collect receives the data points exposed in previous collections regardless of whether new measurements have been recorded:
https://opentelemetry.io/docs/specs/otel/metrics/sdk/#metricreader

_LastValueAggregation dropped its value on every collection, so a synchronous gauge disappeared from the export as soon as one collection interval passed without a set() call.

Fixes #4512

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Unit tests implemented
  • Verified manually on hello-world app

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…ve collections

The MetricReader spec requires that for synchronous instruments with
cumulative aggregation temporality, Collect receives the data points
exposed in previous collections regardless of whether new measurements
have been recorded:
https://opentelemetry.io/docs/specs/otel/metrics/sdk/#metricreader

_LastValueAggregation dropped its value on every collection, so a
synchronous gauge disappeared from the export as soon as one collection
interval passed without a set() call.

Fixes open-telemetry#4512
Fixes open-telemetry#3971
@kacper-wolkiewicz-reef
kacper-wolkiewicz-reef requested a review from a team as a code owner September 7, 2026 11:41
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 7, 2026

Copy link
Copy Markdown

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

  • ✅ login: kacper-wolkiewicz-reef / name: Kacper Wolkiewicz (0a3eb11)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 7, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-09-08 14:20 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@emdneto emdneto moved this to Ready for review in Python PR digest Sep 8, 2026

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

@open-telemetry/python-maintainers I’d consider this a non-breaking public API bug fix, although it intentionally changes the exported telemetry in a way that users may notice.

Just to provide more context to reviewers:

Behavior before this change: A synchronous gauge using cumulative temporality was exported only on the first collection after gauge.set(). If no new value was recorded, the data point disappeared from subsequent collections.

Behavior after this change: The last recorded value is retained and exported on every cumulative collection until it is replaced by another gauge.set() call. Delta temporality and asynchronous instruments (ie., observable gauge) remain unchanged.

Comment thread .changelog/5637.fixed Outdated
Comment thread opentelemetry-sdk/tests/metrics/test_aggregation.py
…moryMetricReader

Collecting twice through an InMemoryMetricReader without recording a new
measurement in between must still export the gauge with its last value.
@lzchen

lzchen commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@emdneto

I agree with the sentiment that this is a bug/spec compliance fix and not really a breaking change.

@lzchen

lzchen commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@kacper-wolkiewicz-reef

Change is good. For the Pr description, does this fully address #3971 thought?

@kacper-wolkiewicz-reef

Copy link
Copy Markdown
Contributor Author
  • fix or feature that would cause existing functionality to not work as expected

Well, according to description form breaking change is "fix or feature that would cause existing functionality to not work as expected", which is true or false depending on what "work as expected" means :D If we mean "as before" then it is breaking change. If "according to spec" then it's not. But the word "fix" suggests me that "as before" is proper interpretation.

But anything works for me.

@kacper-wolkiewicz-reef

Copy link
Copy Markdown
Contributor Author

@kacper-wolkiewicz-reef

Change is good. For the Pr description, does this fully address #3971 thought?

Hmm, when I was searching the issues I found this one and I thought that it may be caused exactly by the same thing. What I did is just tested with the script from the issue after implementing my fix so I assumed it fixed it. But turns out it also works already on the main branch, so apparently someone fixed it before and I just falsely assumed my fix also fixed that one.

I will remove it from the description, sorry for confusion.

@emdneto emdneto moved this from Ready for review to Ready for merge in Python PR digest Sep 10, 2026

@aabmass aabmass 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!

@github-project-automation github-project-automation Bot moved this from Ready for merge to Approved PRs in Python PR digest Sep 10, 2026
@aabmass
aabmass added this pull request to the merge queue Sep 10, 2026
Merged via the queue into open-telemetry:main with commit ab22674 Sep 10, 2026
577 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Gauge read at startup then disapears

4 participants