fast_telemetry/span/mod.rs
1//! Standalone distributed tracing for fast-telemetry.
2//!
3//! Provides lightweight span creation, parent-child nesting, and collection
4//! without the OpenTelemetry SDK dependency. Spans are buffered in thread-local
5//! Vecs (zero atomics on the push path) and exported as OTLP protobuf.
6//!
7//! # Usage
8//!
9//! ```ignore
10//! use std::sync::Arc;
11//! use fast_telemetry::{SpanCollector, SpanKind};
12//!
13//! let collector = Arc::new(SpanCollector::new(8, 1024));
14//!
15//! // Root span (new trace).
16//! let mut root = collector.start_span("handle_request", SpanKind::Server);
17//! root.enter(); // set thread-local for logging
18//! root.set_attribute("http.method", "GET");
19//!
20//! // Child span (inherits trace_id from &root).
21//! {
22//! let mut child = root.child("db_query", SpanKind::Client);
23//! child.set_attribute("db.statement", "SELECT ...");
24//! // child submitted to collector on drop
25//! }
26//!
27//! // For outgoing HTTP requests.
28//! let traceparent = root.traceparent();
29//!
30//! // Logging correlation on the same thread.
31//! let trace_id = fast_telemetry::current_trace_id();
32//! let span_id = fast_telemetry::current_span_id();
33//!
34//! // Exporter drains periodically.
35//! let mut buf = Vec::new();
36//! collector.flush_local();
37//! collector.drain_into(&mut buf);
38//! ```
39//!
40//! Call [`SpanCollector::flush_local`] before [`SpanCollector::drain_into`] when
41//! draining on the same thread that just recorded spans. `SpanCollector::new`
42//! keeps its historical `(shards, capacity)` signature for compatibility, but
43//! those parameters are currently ignored because buffers are managed per thread.
44//!
45//! For manual cross-service propagation, use
46//! [`SpanCollector::start_span_from_traceparent`] on inbound requests and
47//! [`Span::traceparent`](super::Span::traceparent) for outbound headers.
48
49mod collector;
50pub(crate) mod context;
51mod ids;
52mod types;
53
54pub use collector::SpanCollector;
55pub use context::{current_span_id, current_trace_id};
56pub use ids::{SpanId, TraceId};
57pub use types::{CompletedSpan, Span, SpanAttribute, SpanEvent, SpanKind, SpanStatus, SpanValue};