-
Notifications
You must be signed in to change notification settings - Fork 735
fix: start separate runtime for span exporter #3781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: mohammedabdulwahhab <[email protected]>
d741e95 to
03b236f
Compare
WalkthroughLogging initialization was moved to Python module import time (_core), and the logging module gained a static OnceCell-backed Tokio runtime to initialize logging when JSONL logging with OTLP exporter requires an async runtime. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lib/runtime/src/logging.rs (2)
118-120: Document that the logging runtime persists for the process lifetime.The comment mentions the runtime is "only created if needed" but doesn't clarify that it persists until process exit and is never explicitly shut down. This is important for understanding the lifecycle, especially since OTLP batch exporters may not flush remaining spans on abrupt termination.
Consider updating the comment:
-/// Static runtime for OTLP exports and other async logging tasks -/// Only created if needed (when OTLP export is enabled and no runtime exists) +/// Static runtime for OTLP exports and other async logging tasks. +/// Only created if needed (when OTLP export is enabled and no runtime exists). +/// This runtime persists for the process lifetime and is never explicitly shut down. +/// OTLP batch exporter background tasks continue until process exit. static LOGGING_RT: OnceCell<tokio::runtime::Runtime> = OnceCell::new();
717-756: The runtime initialization logic is correct and addresses the tracing regression.The three-branch logic properly handles:
- Using an existing runtime when available
- Creating a dedicated runtime when needed for OTLP exports
- No runtime when only basic logging is required
The batch span processor spawns background tasks onto LOGGING_RT while the runtime is entered (line 742's
_guard), and those tasks continue running on the worker threads after the context is exited.Optional: Consider refactoring duplicated error handling.
The error handling is identical in three places (lines 726-729, 743-746, 750-753). While not critical, this could be deduplicated:
pub fn init() { INIT.call_once(|| { // Check if we need a runtime (only for OTLP exports) let needs_runtime = jsonl_logging_enabled() && otlp_exporter_enabled(); + + let result = if needs_runtime { - if needs_runtime { // Ensure we're in a tokio runtime context for OTLP exporter initialization if tokio::runtime::Handle::try_current().is_ok() { // Already in a runtime, use it - if let Err(e) = setup_logging() { - eprintln!("Failed to initialize logging: {}", e); - std::process::exit(1); - } + setup_logging() } else { // No runtime available, create a dedicated one for logging let rt = LOGGING_RT.get_or_init(|| { tokio::runtime::Builder::new_multi_thread() .worker_threads(1) .thread_name("dynamo-logging") .enable_all() .build() .expect("Failed to create logging runtime") }); // Enter the runtime context and initialize logging let _guard = rt.enter(); - if let Err(e) = setup_logging() { - eprintln!("Failed to initialize logging: {}", e); - std::process::exit(1); - } + setup_logging() } } else { // No runtime needed - just basic logging - if let Err(e) = setup_logging() { - eprintln!("Failed to initialize logging: {}", e); - std::process::exit(1); - } + setup_logging() + }; + + if let Err(e) = result { + eprintln!("Failed to initialize logging: {}", e); + std::process::exit(1); } }); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/bindings/python/rust/lib.rs(1 hunks)lib/runtime/src/logging.rs(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
lib/runtime/src/logging.rs (1)
lib/runtime/src/config.rs (1)
jsonl_logging_enabled(426-428)
lib/bindings/python/rust/lib.rs (2)
lib/runtime/src/logging.rs (1)
init(717-756)lib/runtime/src/storage/key_value_store.rs (1)
init(288-290)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: clippy (lib/runtime/examples)
- GitHub Check: clippy (.)
- GitHub Check: clippy (launch/dynamo-run)
- GitHub Check: tests (.)
- GitHub Check: tests (lib/bindings/python)
- GitHub Check: clippy (lib/bindings/python)
🔇 Additional comments (2)
lib/bindings/python/rust/lib.rs (1)
121-122: LGTM! Early logging initialization correctly isolates the OTLP exporter.The eager initialization at module import time ensures logging is available before any application runtime is created. When OTLP exports are enabled, this will create a dedicated runtime (LOGGING_RT) separate from the DistributedRuntime, which should resolve the tracing regression.
lib/runtime/src/logging.rs (1)
712-716: Excellent documentation of the safe-call semantics.The doc comment clearly explains how the function handles different runtime contexts, which is important given that logging can be initialized from multiple entry points (Python bindings, key_value_store, etc.).
keivenchang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as you've tested this and all the CIs pass, LGTM.
keivenchang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been decided to revert and punt on this PR.
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
As part of the introduction of OTEL, I relocated the logging::init() to happen after the tokio runtime is available (Location). The reason for this is that the export of spans happens async in the event loop. This however caused a regression where logs emitted initially are dropped since the logging stack is initialized further down.
This change reversts the init of the logging stack and creates a dedicated thread to manage the exports.
Summary by CodeRabbit