Skip to content

[SDK] MeterProvider: do not warn in destructor after explicit Shutdown#4085

Open
jaehyeong-cho wants to merge 5 commits into
open-telemetry:mainfrom
jaehyeong-cho:mp-shutdown-no-warning
Open

[SDK] MeterProvider: do not warn in destructor after explicit Shutdown#4085
jaehyeong-cho wants to merge 5 commits into
open-telemetry:mainfrom
jaehyeong-cho:mp-shutdown-no-warning

Conversation

@jaehyeong-cho
Copy link
Copy Markdown
Contributor

Fixes #3511

Changes

Please provide a brief description of the changes here.

  • Add test ensuring duplicate MeterProvider shutdown emits no log
  • Modify MeterProvider to call context shutdown only once

It seems natural for MeterProvider to shut its context down from the destructor, and since MeterContext is a shared object, I think it is meaningful to warn about duplicate Shutdown calls.
However, I think it may not be a good experience that any user who calls the public MeterProvider::Shutdown API will always receive a warning log afterwards, because this isn't really a misuse case.
Therefore, with this PR, I would like to propose limiting MeterProvider to invoking the context shutdown at most once, so that no warning is emitted in the normal usage path.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@jaehyeong-cho jaehyeong-cho requested a review from a team as a code owner May 15, 2026 04:36
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.99%. Comparing base (16b1369) to head (25789e0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4085      +/-   ##
==========================================
- Coverage   82.01%   81.99%   -0.01%     
==========================================
  Files         385      385              
  Lines       16023    16025       +2     
==========================================
- Hits        13139    13138       -1     
- Misses       2884     2887       +3     
Files with missing lines Coverage Δ
sdk/src/metrics/meter_provider.cc 80.77% <100.00%> (+0.77%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

thanks.

{
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
// Shutdown only once
if (shutdown_latch_.test_and_set(std::memory_order_acquire))
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.

Wondering why is this only fixed for ABI v2? The same issue applies to v1 ABI and the same fix could be applied there too.

Copy link
Copy Markdown
Contributor Author

@jaehyeong-cho jaehyeong-cho May 16, 2026

Choose a reason for hiding this comment

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

Thanks for the review. I thought adding a member variable to a public class is ABI-breaking, so I tried to follow abi-version-policy.md and limited the change to ABI v2 only. If we saw this as a bug, I would try applying it to ABI v1 as well, but I thought it is not that serious.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot Shutdown() MeterProvider manually without a warning from destructor

3 participants