Skip to content

[OpenTelemetry] Fix empty histogram data points - #7923

Merged
martincostello merged 5 commits into
open-telemetry:mainfrom
martincostello:gh-7036
Oct 14, 2026
Merged

martincostello merged 5 commits into
open-telemetry:mainfrom
martincostello:gh-7036

Conversation

@martincostello

Copy link
Copy Markdown
Member

Contributes to #7036.

Changes

Set the MetricPoint status flag while still holding the histogram lock in the update paths, so that TakeSnapshot cannot observe a new value without also observing the flag.

Previously, a collection that landed between an update releasing the lock and setting CollectPending cleared the flag, which the update then set again. The next collection exported an empty data point (count of zero, with infinite min and max).

Sum and gauge aggregations are lock-free and still have the same benign race.

Running benchmarks locally show no performance impact from the changes.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, successful build/tests, etc.)
  • Tests added/updated
  • CHANGELOG.md file(s) updated for non-trivial changes
  • Changes in public API reviewed (if applicable)
  • AI usage disclosure:
    • No AI used
    • AI-assisted
    • Bulk AI-generated
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR1

Footnotes

  1. Yes, I can answer maintainer questions about the content of this PR without using AI. ↩

Set the `MetricPoint` status flag while still holding the histogram lock in the update paths, so that `TakeSnapshot` cannot observe a new value without also observing the flag.

Previously, a collection that landed between an update releasing the lock and setting `CollectPending` cleared the flag, which the update then set again. The next collection exported an empty data point (count of zero, with infinite min and max).

Sum and gauge aggregations are lock-free and still have the same benign race.

Contributes to open-telemetry#7036.
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 13, 2026
@opentelemetry-pr-dashboard

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

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-14 19:29 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Comment thread src/OpenTelemetry/CHANGELOG.md Resolved
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (42712de) to head (db50c11).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7923      +/-   ##
==========================================
+ Coverage   92.25%   92.26%   +0.01%     
==========================================
  Files         363      363              
  Lines       20990    20996       +6     
==========================================
+ Hits        19364    19372       +8     
+ Misses       1626     1624       -2     
Flag Coverage Δ
unittests-Project-Experimental 92.39% <100.00%> (+0.01%) ⬆️
unittests-Project-Stable 92.39% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...c/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs 95.00% <100.00%> (+0.07%) ⬆️

... and 1 file with indirect coverage changes

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.

🟡 Changes recommended

The new ordering can strand a concurrently offered exemplar in delta mode until a later measurement.

1 open finding
What changed in this PR

Fixes a race that could export empty delta histogram points.

Changes:

  • Sets histogram collection status under the histogram lock.
  • Adds regression coverage for histogram variants.
  • Documents the behavioral fix.
File Description
src/​OpenTelemetry/​Metrics/​MetricPoint/​MetricPoint.cs Moves status updates into histogram critical sections.
test/​OpenTelemetry.Tests/​Metrics/​MetricPointReclaimTests.cs Tests concurrent updates and collection.
src/​OpenTelemetry/​CHANGELOG.md Records the bug fix.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Address review comments from GitHub Copilot.
Explain trade-off against a suggested refactoring by Codex.

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.

🔵 Needs a closer look

The concurrency-sensitive lock, status, and exemplar ordering warrants final human validation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@martincostello
martincostello marked this pull request as ready for review October 13, 2026 12:45
@martincostello
martincostello requested a review from a team as a code owner October 13, 2026 12:45
@martincostello martincostello added the review-priority Should be prioritized for review label Oct 13, 2026
@martincostello martincostello added this to the v1.20.0 milestone Oct 13, 2026
@martincostello martincostello removed the review-priority Should be prioritized for review label Oct 14, 2026
@martincostello
martincostello added this pull request to the merge queue Oct 14, 2026
Merged via the queue into open-telemetry:main with commit e5b5ac6 Oct 14, 2026
80 checks passed
@martincostello
martincostello deleted the gh-7036 branch October 14, 2026 19:29
This was referenced Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants