Skip to content

Future not resolving with Tonic and SimpleSpanProcessor #785

Closed
@duarten

Description

@duarten

Consider the following otlp configuration:

opentelemetry_otlp::new_exporter()
        .tonic()
        .with_endpoint(endpoint.as_str())
        .with_metadata(metadata)
        .with_tls_config(
            tonic::transport::ClientTlsConfig::new().domain_name(endpoint.host_str().unwrap()),
        )
        .with_protocol(opentelemetry_otlp::Protocol::Grpc)
        .with_timeout(std::time::Duration::from_secs(3))

When using SimpleSpanProcessor (through with_simple_exporter), eventually the program reaches a point where the future actually exporting the span never resolves. It's this line: the thread dequeues the span, and block_on never returns. It seems this is triggering a deadlock.

I'm using tracing-rs (with the workaround in #473) on top and opentelemetry-otlp configured with ["tonic", "tls", "tls-roots"] .

Curiously, if I use the following very simple processor, everything works correctly:

#[derive(Debug)]
struct SimplerProcessor<E: SpanExporter + Send + Sync> {
    inner: std::sync::Arc<std::sync::Mutex<E>>,
}

impl<E: SpanExporter + Sync + Send> SpanProcessor for SimplerProcessor<E> {
    fn on_start(&self, _span: &mut Span, _cx: &opentelemetry::Context) {
    }

    fn on_end(&self, span: SpanData) {
        tokio::task::block_in_place(|| {
            tokio::runtime::Handle::current()
                .block_on(self.inner.lock().unwrap().export(vec![span]))
        })
        .expect("span not sent");
    }

    fn force_flush(&self) -> opentelemetry::trace::TraceResult<()> {
        Ok(())
    }

   fn shutdown(&mut self) -> opentelemetry::trace::TraceResult<()> {
        Ok(())
    }
}

Does any of this ring any bells?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-traceArea: issues related to tracing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions