From 2d7b65e8eb7fd0f41cd8ff76bd9f7677fff3ec27 Mon Sep 17 00:00:00 2001 From: bin Date: Fri, 8 Oct 2021 21:29:47 +0800 Subject: [PATCH] agent: flush root span before process finish Variables in rust will be dropped at the end of the function. In function real_main the trace will be shut down by `tracer::end_tracing()`, but at this time the root span is in an active state, so this root span will not be sent to the trace collector. This can be fixed by dropping the root span manually. Fixes: #2812 Signed-off-by: bin --- src/agent/src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 4ee6dadace..a3e9dd58fb 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -200,12 +200,12 @@ async fn real_main() -> std::result::Result<(), Box> { let _ = tracer::setup_tracing(NAME, &logger, &config)?; } - let root = span!(tracing::Level::TRACE, "root-span", work_units = 2); + let root_span = span!(tracing::Level::TRACE, "root-span"); // XXX: Start the root trace transaction. // // XXX: Note that *ALL* spans needs to start after this point!! - let _enter = root.enter(); + let span_guard = root_span.enter(); // Start the sandbox and wait for its ttRPC server to end start_sandbox(&logger, &config, init_mode, &mut tasks, shutdown_rx.clone()).await?; @@ -235,6 +235,10 @@ async fn real_main() -> std::result::Result<(), Box> { } } + // force flushing spans + drop(span_guard); + drop(root_span); + if config.tracing != tracer::TraceType::Disabled { tracer::end_tracing(); }