Skip to content

Missing events when using tracing-opentelemetry with threads #1885

Answered by davidbarsky
bjchambers asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry for the delay in responding. First things first: I don't recommend spawning a thread inside an async function; I would do this outside of that context or use tokio::task::spawn_blocking if benchmarks indicate that it's worthwhile to use. Freely spawning threads inside of a Tokio context (or any other futures executor) risks blocking the thread by not allowing the task to suspend, leading to worse performance.

I'm able to get the event with the message "THIS EVENT DOES NOT SHOW UP" with the following code:

#[tracing::instrument]
fn some_fn() {
    info!("In some_fn");

    let span = info_span!("Inner span");

    let thread = std::thread::spawn(move || {
        let _span = span.ent…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hawkw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1859 on February 02, 2022 17:23.