Skip to content

Use Dedicated Threads for BatchExportProcessor and PeriodicReader #2386

Closed
@cijothomas

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.

  1. Dedicated Background Threads as Default:

    • Both BatchExportProcessor and PeriodicReader will use dedicated background threads by default.
  2. 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.
  3. Networking Library Issues:

    • Networking libraries like reqwest, hyper, and tonic used by our core Exporter (OTLP) present challenges when operating outside async runtimes:
      • reqwest: Replace with reqwest-blocking for dedicated threads. Given that the thread being blocked is OpenTelemetry's own background thread, this should not be a concern.
      • hyper and tonic: 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.

Advantages of Dedicated Threads

  1. Improved Reliability:

  2. 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.
  3. Simplified Debugging:

    • Debugging issues like "telemetry not flowing" becomes easier when telemetry processing occurs on a known, dedicated thread.
  4. 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

  1. 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.
  2. 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

  1. 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.
  2. If there is a need to use runtime like tokio, update the feature flags to their "experimental" prefixed versions..

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions