Skip to content

chore: (For Discussion) Dynamic runtime detection & block_on abstraction#3412

Draft
scottgerring wants to merge 3 commits intoopen-telemetry:mainfrom
scottgerring:scottgerring/dynamic-runtime-detection-v2
Draft

chore: (For Discussion) Dynamic runtime detection & block_on abstraction#3412
scottgerring wants to merge 3 commits intoopen-telemetry:mainfrom
scottgerring:scottgerring/dynamic-runtime-detection-v2

Conversation

@scottgerring
Copy link
Copy Markdown
Member

@scottgerring scottgerring commented Mar 11, 2026

Fixes #2643, stabilising Runtime trait. Note that i've not removed the experimental flags, but will do so when we're happy with an approach. Note that i've not removed the experimental flags, but will do so when we're happy with an approach.

This is a light touch approach to stabilising the runtime trait.
We do this by consolidating Tokio and TokioCurrentThread into a single Tokio runtime type that auto-detects the active Tokio runtime flavour at call time using Handle::try_current() and runtime_flavor():

  • Multi-threaded runtime: spawns directly via tokio::spawn
  • Current-thread runtime: spawns on a dedicated OS thread with its own Tokio runtime to avoid deadlocks
  • No runtime available: falls back to an OS thread with a new Tokio runtime

This eliminates the rt-tokio-current-thread feature flag entirely — users just enable rt-tokio and the right behavior happens automatically.

Additionally adds a block_on method to the Runtime trait, which is also runtime-flavour-aware: on current-thread it uses std::thread::scope to block on a separate thread, avoiding deadlocks. This replaces ad-hoc futures_executor::block_on calls scattered through processors.

this aims to be a minimal, focused change - keeps the existing oneshot-based shutdown signalling.

@scottgerring scottgerring requested a review from a team as a code owner March 11, 2026 11:45
@scottgerring scottgerring changed the title draft for discussion: Dynamic runtime detection & block_on abstraction chore: (For Discussion) Dynamic runtime detection & block_on abstraction Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.2%. Comparing base (d91b847) to head (90aba49).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/runtime.rs 86.9% 6 Missing ⚠️
.../src/metrics/periodic_reader_with_async_runtime.rs 91.6% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3412   +/-   ##
=====================================
  Coverage   83.1%   83.2%           
=====================================
  Files        128     128           
  Lines      24899   24921   +22     
=====================================
+ Hits       20715   20743   +28     
+ Misses      4184    4178    -6     

☔ View full report in Codecov by Sentry.
📢 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

Development

Successfully merging this pull request may close these issues.

Stabilize support for async runtimes

1 participant