Open
Description
Feature Request
Crates
tracing_opentelemetry
Motivation
I'd like to create a span, set an OpenTelemetry context as the parent, and then use the span in calls like instrument
, without having to create a named let binding for the span.
Proposal
I'd like to propose a function OpenTelemetrySpanExt::with_parent
, which acts exactly like set_parent
, but accepts self
and returns Self
.
fn with_parent(self, cx: opentelemetry::Context) -> Self {
self.set_parent(cx);
self
}
Such a function would allow code like this:
async { ... }.instrument(info_span!("span details").with_parent(context)).await
Alternatives
The tracing macros could have "native" support for OpenTelemetry contexts as parents:
async { ... }.instrument(info_span!(parent: context, "span details")).await
That seems much harder to implement, though.