pub struct Span { /* private fields */ }Expand description
A single open span. Create one with span or client_span (or
Span::new for full control over SpanKind); it becomes the
“current” span on this thread until it’s dropped (or Span::end is
called explicitly, which is equivalent).
Nesting: creating a Span while another is already active makes the new
one its child — the child inherits the parent’s trace_id and sampling
decision, and parent_span_id() is the parent’s span_id(). Dropping the
child makes the parent “current” again.
Not Send: a Span must be dropped on the thread that created it, since
dropping pops a thread-local stack — moving one to another thread and
dropping it there would corrupt that thread’s stack.
§Example
use rust_web_server::otel;
let span = otel::span("db.query");
span.set_attribute("db.statement", "SELECT 1");
// ... do the work ...
span.end(); // or just let it drop at the end of scopeImplementations§
Source§impl Span
impl Span
Sourcepub fn new(name: &str, kind: SpanKind) -> Span
pub fn new(name: &str, kind: SpanKind) -> Span
Start a new span with an explicit SpanKind. Prefer span or
client_span for the common cases.
Sourcepub fn set_attribute(&self, key: &str, value: impl Into<AttributeValue>)
pub fn set_attribute(&self, key: &str, value: impl Into<AttributeValue>)
Attach a key/value attribute. Repeated keys are appended, not deduplicated — matching this module’s existing “loosely OTLP” style.
Sourcepub fn record_error(&self, message: &str)
pub fn record_error(&self, message: &str)
Mark this span as failed and attach an error.message attribute.
pub fn trace_id(&self) -> [u8; 16]
pub fn span_id(&self) -> [u8; 8]
pub fn parent_span_id(&self) -> Option<[u8; 8]>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more