davidB / tracing-opentelemetry-instrumentation-sdk

Middlewares and tools to integrate axum + tracing + opentelemetry
Creative Commons Zero v1.0 Universal
152 stars 44 forks source link

init-tracing-opentelemetry: Regression on flushing all traces at program termination #184

Closed nshalman closed 2 days ago

nshalman commented 5 days ago

I believe this to be a consequence of https://github.com/open-telemetry/opentelemetry-rust/issues/1961

Using these versions:

[dependencies]
init-tracing-opentelemetry = { version = "0.19", features = [
  "otlp",
  "tls",
  "tracing_subscriber_ext",
] }
opentelemetry = "0.23"
tokio = { version = "1.38", features = ["full"] }
tracing = "0.1.40"

This code works (I can get a trace):

#[tracing::instrument]
async fn hello() -> () {
    tracing::info!("Hello World!");
}

#[tokio::main]
async fn main() {
    match std::env::var("OTEL_SERVICE_NAME") {
        Ok(_) => (),
        Err(_) => std::env::set_var("OTEL_SERVICE_NAME", "hello"),
    };
    init_tracing_opentelemetry::tracing_subscriber_ext::init_subscribers().expect("Tracing setup");
    hello().await;
    opentelemetry::global::shutdown_tracer_provider();
}

But when I change to these versions, the trace doesn't get emitted:

[dependencies]
init-tracing-opentelemetry = { version = "0.24", features = [
  "otlp",
  "tls",
  "tracing_subscriber_ext",
] }
opentelemetry = "0.27"
tokio = { version = "1.38", features = ["full"] }
tracing = "0.1.40"

With this grossest of workarounds I can get the trace to show up again:

@@ -12,4 +12,5 @@ async fn main() {
     init_tracing_opentelemetry::tracing_subscriber_ext::init_subscribers().expect("Tracing setup");
     hello().await;
     opentelemetry::global::shutdown_tracer_provider();
+    std::thread::sleep(std::time::Duration::from_millis(8000));
 }
pitoniak32 commented 4 days ago

Hey @nshalman, I found a little cleaner of a work around and described it here if you are interested: https://github.com/open-telemetry/opentelemetry-rust/issues/1961#issuecomment-2491325681