Skip to content

Commit

Permalink
🐛 Force shutdown_tracer_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomAub committed Jun 9, 2024
1 parent f533705 commit 62db3f9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/axum-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ async fn proxy_handler(Path((service, path)): Path<(String, String)>) -> impl In
}

async fn shutdown_signal() {
use std::sync::mpsc;
use std::{thread, time::Duration};

let ctrl_c = async {
tokio::signal::ctrl_c()
.await
Expand All @@ -86,5 +89,13 @@ async fn shutdown_signal() {
}

tracing::warn!("signal received, starting graceful shutdown");
opentelemetry::global::shutdown_tracer_provider();
let (sender, receiver) = mpsc::channel();
let _ = thread::spawn(move || {
opentelemetry::global::shutdown_tracer_provider();
sender.send(()).ok()
});
let shutdown_res = receiver.recv_timeout(Duration::from_millis(2_000));
if shutdown_res.is_err() {
tracing::error!("failed to shutdown OpenTelemetry");
}
}

0 comments on commit 62db3f9

Please sign in to comment.