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.