Skip to content

Commit

Permalink
Simplify flush on drop for trace provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryn committed Apr 22, 2022
1 parent ef6b533 commit 0f5dd0f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions apollo-router/src/plugins/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,13 @@ impl Drop for Telemetry {
// Tracer providers must be flushed. This may happen as part of otel if the provider was set
// as the global, but may also happen in the case of an failed config reload.
// If the tracer prover is present then it was not handed over so we must flush it.
// The magic incantation seems to be that the flush MUST happen within a tokio runtime,
// and then within a spawn blocking.
// The magic incantation seems to be that the flush MUST happen in a separate thread.
::tracing::debug!("flushing telemetry");
std::thread::spawn(|| {
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap();
runtime.block_on(async {
let jh = tokio::task::spawn_blocking(move || {
opentelemetry::trace::TracerProvider::force_flush(&tracer_provider);
});
futures::executor::block_on(jh).expect("failed to flush tracer provider");
std::thread::spawn(|| async {
let jh = tokio::task::spawn_blocking(move || {
opentelemetry::trace::TracerProvider::force_flush(&tracer_provider);
});
futures::executor::block_on(jh).expect("failed to flush tracer provider");
});
}

Expand Down

0 comments on commit 0f5dd0f

Please sign in to comment.