Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
 - use spawn_blocking() in preference to spawning a thread
 - update the comment block to refer directly to issue #331
  • Loading branch information
garypen committed Jan 19, 2022
1 parent eeb443a commit bef9051
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apollo-router/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ pub(crate) fn try_initialize_subscriber(

// The call to set_tracer_provider() manipulate a sync RwLock.
// Even though this code is sync, it is called from within an
// async context. If we don't do this in a separate thread,
// it will cause issues with the async runtime that prevents
// the router from working correctly.
let _ = std::thread::spawn(|| {
// async context. If we don't call set_tracer_provider() from
// spawn_blocking() (or from a separate thread), it will cause
// issues with the async runtime which results in a router
// which no longer responds to input events.
// See https://github.com/apollographql/router/issues/331
// for more details and description.
let jh = tokio::task::spawn_blocking(|| {
opentelemetry::global::set_tracer_provider(provider);
})
.join();
});
futures::executor::block_on(jh)?;

let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);

Expand Down

0 comments on commit bef9051

Please sign in to comment.