opentelemetry-rust
opentelemetry-rust copied to clipboard
Error using opentelemetry_otlp::new_exporter().tonic()
I'm regularly getting an error when sending traces:
OpenTelemetry trace error occurred. Exporter otlp encountered the following error(s): the grpc server returns error (Unknown error): , detailed error message: transport error
Using this setup:
opentelemetry::global::set_text_map_propagator(XrayPropagator::default());
match tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
{
Ok(runtime) => {
runtime.block_on(async {
match opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(opentelemetry_otlp::new_exporter().tonic())
.with_trace_config(
sdktrace::config()
.with_sampler(sdktrace::Sampler::AlwaysOn)
.with_id_generator(sdktrace::XrayIdGenerator::default()),
)
.install_simple()
{
Ok(tracer) => {
// initialize global subscriber
}
Err(e) => {
// do something
}
}
});
}
Err(e) => {
// do something
}
}
}
When I send a trace within the runtime it seems to be working but not from outside the runtime.
My understanding is that the exporter is set up and the subscriber is globally initialized on the current thread. It seems to be an error with tonic that after the exporter is built and the subscriber is initialized, the grpc transport layer immediately closes after the runtime finishes.
Initially, I had assumed that the exporter does not need to be within a runtime as the documentation also seems to initialize it synchronously but without it shows this build error with the following cargo dependencies:
thread 'opentelemetry-exporter' panicked at 'dispatch dropped without returning error'
tokio = { version = "^1.16", features = ["full"] }
opentelemetry = "0.17.0"