Skip to main content

Module span

Module span 

Source
Expand description

Standalone distributed tracing for fast-telemetry.

Provides lightweight span creation, parent-child nesting, and collection without the OpenTelemetry SDK dependency. Spans are buffered in thread-local Vecs (zero atomics on the push path) and exported as OTLP protobuf.

§Usage

use std::sync::Arc;
use fast_telemetry::{SpanCollector, SpanKind};

let collector = Arc::new(SpanCollector::new(8, 1024));

// Root span (new trace).
let mut root = collector.start_span("handle_request", SpanKind::Server);
root.enter(); // set thread-local for logging
root.set_attribute("http.method", "GET");

// Child span (inherits trace_id from &root).
{
    let mut child = root.child("db_query", SpanKind::Client);
    child.set_attribute("db.statement", "SELECT ...");
    // child submitted to collector on drop
}

// For outgoing HTTP requests.
let traceparent = root.traceparent();

// Logging correlation on the same thread.
let trace_id = fast_telemetry::current_trace_id();
let span_id = fast_telemetry::current_span_id();

// Exporter drains periodically.
let mut buf = Vec::new();
collector.flush_local();
collector.drain_into(&mut buf);

Call SpanCollector::flush_local before SpanCollector::drain_into when draining on the same thread that just recorded spans. SpanCollector::new keeps its historical (shards, capacity) signature for compatibility, but those parameters are currently ignored because buffers are managed per thread.

For manual cross-service propagation, use SpanCollector::start_span_from_traceparent on inbound requests and Span::traceparent for outbound headers.

Structs§

CompletedSpan
A finalized span with start and end timestamps, ready for export.
Span
An active span that accumulates events and attributes.
SpanAttribute
A key-value attribute attached to a span.
SpanCollector
Thread-local span collector with zero-atomic submit path.
SpanEvent
A timestamped event recorded during a span’s lifetime.
SpanId
64-bit span identifier. Unique within a trace.
TraceId
128-bit trace identifier. All spans in a distributed trace share the same TraceId.

Enums§

SpanKind
Indicates the role of a span in the trace.
SpanStatus
Final status of a span.
SpanValue
Typed attribute value.

Functions§

current_span_id
Get the span ID of the currently entered span on this thread, if any.
current_trace_id
Get the trace ID of the currently entered span on this thread, if any.