pub struct Span { /* private fields */ }Expand description
An active span that accumulates events and attributes.
Created via SpanCollector::start_span (root) or Span::child (nested).
Submits a CompletedSpan to the collector when dropped or when
end() is called explicitly.
Internally holds Option<CompletedSpan> with end_time_ns = 0 until
the span finishes. On drop, end_time_ns is set and the span is submitted
— no field-by-field move between separate structs.
Implementations§
Source§impl Span
impl Span
Sourcepub fn child(&self, name: impl Into<Cow<'static, str>>, kind: SpanKind) -> Span
pub fn child(&self, name: impl Into<Cow<'static, str>>, kind: SpanKind) -> Span
Create a child span inheriting the trace ID and collector from this span.
The child’s parent_span_id is set to this span’s span_id.
If this span is a no-op (sampled out), the child is also a no-op.
Sourcepub fn enter(&mut self) -> &mut Self
pub fn enter(&mut self) -> &mut Self
Set this span as the thread-local “current span” for logging integration.
The thread-local context is cleared when this span drops. Nested calls properly restore the previous context.
Sourcepub fn add_event(
&mut self,
name: impl Into<Cow<'static, str>>,
attributes: Vec<SpanAttribute>,
)
pub fn add_event( &mut self, name: impl Into<Cow<'static, str>>, attributes: Vec<SpanAttribute>, )
Add a timestamped event to this span.
Takes ownership of the attributes vector to avoid cloning.
Sourcepub fn add_simple_event(&mut self, name: impl Into<Cow<'static, str>>)
pub fn add_simple_event(&mut self, name: impl Into<Cow<'static, str>>)
Add a timestamped event with no attributes.
Sourcepub fn set_attribute(
&mut self,
key: impl Into<Cow<'static, str>>,
value: impl Into<SpanValue>,
)
pub fn set_attribute( &mut self, key: impl Into<Cow<'static, str>>, value: impl Into<SpanValue>, )
Set a span attribute.
Sourcepub fn set_status(&mut self, status: SpanStatus)
pub fn set_status(&mut self, status: SpanStatus)
Set the span status.
Sourcepub fn traceparent(&self) -> String
pub fn traceparent(&self) -> String
Encode this span’s context as a W3C traceparent header for outgoing requests.
Returns an empty string for no-op (sampled-out) spans.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Span
impl !RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl !UnwindSafe for Span
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request