Description
What happened?
Consider this example code:
(I am using tracing_opentelemetry, but it should be reproducible without it)
let telemetry = {
// Create a new OpenTelemetry trace pipeline that prints to stdout
let provider = TracerProvider::builder()
.with_simple_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint("http:localhost:4317")
.with_timeout(Duration::from_secs(3))
.build_span_exporter()?,
)
.with_config(opentelemetry_sdk::trace::Config::default().with_resource(
Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"service-api",
)]),
))
.build();
let tracer = provider.tracer("service-api");
// Create and return a tracing layer with the configured tracer
tracing_opentelemetry::layer().with_tracer(tracer)
};
Since the provider is not used afterwards, it is very easy to accidentally drop it when executing inside a function or conditional block.
There is no compiler warning or any documentation note regarding this behaviour or that it must be kept alive manually. This results in very hard to debug problem, because code that compiles fine without a warning can stop working just by moving a value into a scope.
I suspect this is because TracerProvider
creates the Tracer
by downgrading the Arc
to a Weak
.
IMHO this should at the very least be documented on the TracerProvider
struct, maybe a warning can be added to the Drop Implementation, too.
API Version
0.15
SDK Version
0.22.1
What Exporters are you seeing the problem on?
No response
Relevant log output
No response