Shut down the replaced MeterProvider in get_otel_logger() - #71800
Draft
frank-ye wants to merge 1 commit into
Draft
Shut down the replaced MeterProvider in get_otel_logger()#71800frank-ye wants to merge 1 commit into
frank-ye wants to merge 1 commit into
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
Re-initialising the OTel metrics pipeline in a long-lived process left the previous pipeline running. The outgoing provider owns a PeriodicExportingMetricReader whose constructor already started a daemon export thread, and it is built with shutdown_on_exit=False, so nothing reaped it. The abandoned reader kept exporting while its instruments were no longer recorded to, freezing its cumulative totals and republishing them under the same resource with a different start_time_unix_nano. Shut the outgoing provider down before installing the replacement. shutdown() force flushes first, so the final datapoints are not lost.
frank-ye
force-pushed
the
fix/otel-shutdown-replaced-meterprovider
branch
from
August 18, 2026 20:33
2d55369 to
20819b9
Compare
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-initialising the OTel metrics pipeline inside a long-lived process leaves the previous
pipeline running and exporting.
#64703 resets the SDK's
Once()guard so thatset_meter_provider()genuinely succeeds on asecond call. That fixed metrics being silently dropped in forked children (#64690). What it does
not do is shut down the provider it replaces.
The outgoing provider owns a
PeriodicExportingMetricReader, and that reader's constructor hasalready started a daemon thread which exports on its own interval. The provider is built with
shutdown_on_exit=False, so nothing ever reaps it. The abandoned reader therefore keepsexporting, but its instruments are no longer recorded to, so its cumulative totals freeze. It
republishes those frozen totals indefinitely, under the same resource, with a different
start_time_unix_nano.A consumer then receives two conflicting cumulative streams for one series: one climbing
correctly, one stuck at whatever the value was when the pipeline was replaced. Backends that must
collapse them to a single series alternate between the two, which reads as a large spurious rate
spike; backends that reject out-of-order samples can drop the counter entirely.
This is invisible under delta temporality, because the abandoned reader honestly reports "nothing
new" forever. It only surfaces once counters are reported as cumulative.
Reproduction
Against
opentelemetry-sdk==1.42.1, mimickingget_otel_logger(): build a provider, record 48 toa counter, reset the
Once()guard, install a second provider, record 1000 to the counter.Before:
After:
The new test in
test_otel_logger.pyasserts the process does not accumulate exporter threadsacross a re-initialisation. It fails without this change (
leaked_readers=1) and passes with it.Fix
Shut down the outgoing provider before installing the replacement.
MeterProvider.shutdown()force-flushes first, so the final datapoints are not lost, which keeps the guarantee #64703 was
written to restore.
shared/observability/tests/observability/metrics/test_otel_logger.py)Was generative AI tooling used to co-author this PR?
Claude Code (Opus)