Skip to content

fix(sdk): spawn periodic reader worker at reader build time#3605

Open
karan-vk wants to merge 2 commits into
open-telemetry:mainfrom
karan-vk:fix/periodic-reader-runtime
Open

fix(sdk): spawn periodic reader worker at reader build time#3605
karan-vk wants to merge 2 commits into
open-telemetry:mainfrom
karan-vk:fix/periodic-reader-runtime

Conversation

@karan-vk

Copy link
Copy Markdown

Fixes #3601

Changes

periodic_reader_with_async_runtime::PeriodicReader stored its spawn closure and only ran it inside register_pipeline, so the worker task landed on whatever tokio runtime was ambient when the meter provider was built rather than when the reader, which takes the runtime argument, was built. Building the reader and the provider in different contexts could deadlock or panic.

The worker is now spawned eagerly in build(), matching the async-runtime BatchSpanProcessor and BatchLogProcessor, and ProducerOrWorker is reduced to a plain Option producer. Added a regression test that builds the reader inside a runtime and the provider outside of one; it panics without this fix.

Behavior note: a reader that is built but never attached to a provider now runs its interval ticker and logs collect errors, where before the worker was never spawned. This matches the existing behavior of the async-runtime batch processors.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable) - no public API changes

The async-runtime PeriodicReader stored its spawn closure and only ran
it inside register_pipeline, so the worker task landed on whatever
tokio runtime was ambient when the meter provider was built, not when
the reader taking the runtime argument was built. Building the reader
and provider in different contexts could deadlock or panic.

Spawn the worker eagerly in build(), matching the async-runtime
BatchSpanProcessor and BatchLogProcessor, and reduce
ProducerOrWorker to a plain optional producer.

Fixes open-telemetry#3601
@karan-vk
karan-vk requested a review from a team as a code owner July 24, 2026 08:33
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.3%. Comparing base (0e78170) to head (de07fdf).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3605     +/-   ##
=======================================
+ Coverage   83.2%   83.3%   +0.1%     
=======================================
  Files        130     130             
  Lines      28246   28286     +40     
=======================================
+ Hits       23506   23583     +77     
+ Misses      4740    4703     -37     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

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

Labels

None yet

Projects

None yet

1 participant