Use Dedicated Threads for BatchExportProcessor and PeriodicReader #2386
Closed
Description
For the 1.0 release:
Use dedicated threads for BatchExportProcessor and PeriodicReader. This is done to improve usability, telemetry reliability, simplify debugging, and eliminate issues stemming from asynchronous runtime dependencies and/or improper usage. Existing runtime integrations (eg: rt-tokio
etc. will remain available under an experimental feature flag to ensure backward compatibility and allow time for further refinement.
-
Dedicated Background Threads as Default:
- Both
BatchExportProcessor
andPeriodicReader
will use dedicated background threads by default.
- Both
-
Existing Runtime - Offer under Experimental Feature flag:
- For platforms with threading restrictions or users preferring OpenTelemetry to integrate with their existing async runtimes, we will continue to support current runtime-based configurations. These configurations will be moved under an experimental feature flag. This approach ensures that existing users are not disrupted while providing time to polish the APIs and functionalities beyond 1.0. Post 1.0, these can be advanced to be offered under stable feature flags.
-
Networking Library Issues:
- Networking libraries like
reqwest
,hyper
, andtonic
used by our core Exporter (OTLP) present challenges when operating outside async runtimes:reqwest
: Replace withreqwest-blocking
for dedicated threads. Given that the thread being blocked is OpenTelemetry's own background thread, this should not be a concern.hyper
andtonic
: Evaluate their compatibility with dedicated threads and find appropriate solutions. If certain clients cannot be supported, users requiring those clients can revert to the experimental runtime feature.
- Networking libraries like
Advantages of Dedicated Threads
-
Improved Reliability:
- Telemetry processing becomes independent of shared thread pools (e.g., Tokio), ensuring it continues even when pools are saturated, avoiding issues like How to debug metrics not being sent to otel-collector #2058 (comment) and [Feature]: Support Metrics, BatchProcessor without async runtime #1437 (comment)
-
Eliminate a class of bugs:
- Many shutdown and deadlock issues reported stem from incorrect use or combinations of async runtimes. Dedicated threads, combined with defaults that work for majority scenarios, eliminate this class of issues/bugs.
-
Simplified Debugging:
- Debugging issues like "telemetry not flowing" becomes easier when telemetry processing occurs on a known, dedicated thread.
-
Ease of onboarding
- By offering reasonable defaults, it is easy to onboard quickly to OpenTelemetry Rust + OTLP. Users do not have to worry about which async runtimes and networking client combinations to use. Currently there are no defaults and users are required to pick runtimes.
Implementation Plan
-
Start with Metrics:
- Leverage the existing
PeriodicReaderWithOwnThread
, which already spawns its own thread, as a starting point. - Make it the default, and make sure OTLP Exporters can be used.
- Leverage the existing
-
BatchExportProcessor:
- Resurrect the existing work-in-progress pull request (PR) to enable dedicated thread support. This may be done in parallel as well. Focus on Logs only for 1.0
Migration for users
- If users want telemetry to work with OTLP, remove all feature flags (like rt-tokio) and stop passing the
rt
argument to BatchExportProcessor and PeriodicReader. The defaults are sufficient for most scenarios. - If there is a need to use runtime like tokio, update the feature flags to their "experimental" prefixed versions..
Metadata
Assignees
Labels
No labels