Skip to content

tracing_opentelemetry: Version of OpenTelemetrySpanExt::set_parent that returns self #1412

Open
@joshtriplett

Description

@joshtriplett

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.

Metadata

Metadata

Assignees

Labels

crate/opentelemetryRelated to the `tracing-opentelemetry` crate.kind/featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions