Skip to content

[OpenTelemetry] Fix assertion failures in debug #6304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martincostello
Copy link
Member

Fixes #6300

Changes

Avoid failing assertions in debug by skipping collecting a metrics batch if the MeterProvider has not yet been initialized.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 11:22
@martincostello martincostello requested a review from a team as a code owner June 4, 2025 11:22
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Jun 4, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes assertion failures in debug mode by skipping the metrics batch collection when the MeterProvider has not yet been initialized.

  • Replaces Debug.Assert checks with a conditional null check
  • Returns a default batch when required metrics are not set

Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.76%. Comparing base (e21e9cc) to head (97b13f6).

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6304   +/-   ##
=======================================
  Coverage   86.76%   86.76%           
=======================================
  Files         258      258           
  Lines       11879    11881    +2     
=======================================
+ Hits        10307    10309    +2     
  Misses       1572     1572           
Flag Coverage Δ
unittests-Project-Experimental 86.62% <100.00%> (+0.24%) ⬆️
unittests-Project-Stable 86.37% <100.00%> (-0.26%) ⬇️

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

Files with missing lines Coverage Δ
...rc/OpenTelemetry/Metrics/Reader/MetricReaderExt.cs 91.96% <100.00%> (+0.14%) ⬆️

@rajkumar-rangaraj
Copy link
Contributor

@CodeBlanch Could you please review this PR? In my opinion Debug.Assert shouldn't be a concern here.

Avoid failing assertions in debug by skipping collecting a metrics batch if the MeterProvider has not yet been initialized.

Resolves open-telemetry#6300.
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.

[bug] Debug.Assert failure in MetricReaderEx.cs
2 participants