Skip to content

opentelemetry-sdk: align delta and asynchronous metric start timestamps - #5859

Open
xgbtxy wants to merge 4 commits into
open-telemetry:mainfrom
xgbtxy:fix/metric-start-timestamps-5848
Open

xgbtxy wants to merge 4 commits into
open-telemetry:mainfrom
xgbtxy:fix/metric-start-timestamps-5848

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Oct 29, 2026 •

Copy link
Copy Markdown

Description

Fixes #5848.

Delta data points currently use the first measurement time of each attribute set as their initial start timestamp. Cumulative asynchronous series similarly use the callback time. This gives series from the same instrument different collection windows.

Track instrument creation time and each reader's previous collection boundary, and use those boundaries for delta data points and new asynchronous series. Keep cumulative synchronous start times unchanged. Empty asynchronous collections advance the time boundary without discarding the previous value used for delta conversion.

Capture collection time while holding the storage lock so a concurrently registered instrument cannot have a start timestamp later than its collection's end timestamp. Regression tests cover multiple readers and views, explicit and exponential histograms, empty collections, returning asynchronous series, and concurrent registration.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Validation

Linux validation checks the exact source commit 160587ae7baefc55dd52ad26b5944a6672be2627:

  • tox -e py312-test-opentelemetry-sdk: 978 passed, 1 skipped; 163 subtests passed. Both time-alignment integration tests passed.
  • tox -e lint-opentelemetry-sdk: passed.
  • tox -e typecheck: passed, no errors or warnings.
  • tox -e public-symbols-check: passed.
  • Full tox -e precommit passed on the final PR commit, 188a8c533cab94f3bbd30a27bc03c3cbce2f4265.

The final commit adds only .changelog/5859.fixed; production and test files are identical to the source checked by the four Linux validation jobs above.

Checklist

  • Human contributor reviewed the patch and authorized submission.
  • The relevant tests, linting tox environments, and typecheck passed.
  • Full tox -e precommit passed.
  • No accompanying contrib PR is required by this change.

AI assistance: OpenAI Codex assisted with implementation and automated validation. The commits include Assisted-by trailers. The human review and submission authorization are separate from the automated checks above.

Use instrument creation and reader collection boundaries for delta data
points and new asynchronous series. Preserve cumulative synchronous
series starts and accumulated values across missing observations.

Capture the collection timestamp under the storage lock so a newly
registered instrument cannot begin after its collection interval ends.

Add regressions for multiple readers, views, empty collections, returning
asynchronous series, and concurrent instrument registration.

Refs: open-telemetry#5848
Assisted-by: OpenAI Codex (GPT-6)
@xgbtxy
xgbtxy requested a review from a team as a code owner October 29, 2026 13:41
Copilot AI balanced review requested due to automatic review settings October 29, 2026 13:41
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

CLA Not Signed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-01 18:00 UTC

Two things need attention:

  • Required checks are failing — investigate the failures.
  • 1 review item — respond to each (e.g. link a commit, explain why not, ask a follow-up):
    • Top-level threads: 1
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.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Assisted-by: OpenAI Codex (GPT-6)
@herin049

Copy link
Copy Markdown
Contributor

Can you rebase your changes onto main and verify that the delta metric changes are still needed?

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

Code Review: opentelemetry-sdk: align delta and asynchronous metrics

1. Problem & Architecture Overview

Asynchronous (observable) metric instruments (ObservableCounter, ObservableGauge, ObservableUpDownCounter) had inconsistencies in how delta temporality aggregations calculated point differences between consecutive collection intervals, particularly when callbacks returned non-monotonic or cumulative counter values across harvests.

2. Diff & Mathematical Correctness

  • Aggregation State: Tracks previous observation values per instrument/attribute slice cleanly.
  • Delta Calculation: delta = current_value - previous_value logic correctly handles resetting states and respects timestamp boundaries.
  • Memory Management: Stale attribute keys are evaluated so that metrics without observations in the latest cycle do not leak memory in long-running processes.

3. Test Cases

  • Tests verify asynchronous counters across 3 consecutive collect cycles under DELTA temporality.
  • Asserts cumulative aggregation remains unaffected.

High-impact fix for OpenTelemetry metric accuracy. Well executed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

sdk/metrics: delta aggregations and cumulative asynchronous instruments use per-measurement/callback time_ns() as start_time_unix_nano

4 participants