krabka_trace_context/lib.rs
1//! W3C Trace Context propagation shared by Krabka's wire-protocol crates.
2//!
3//! This crate is the single place where a trace context crosses a Krabka
4//! process boundary. It covers the three shapes those boundaries take:
5//!
6//! - **Kafka record headers**: [`current_trace_headers`] injects the
7//! `traceparent` and `tracestate` pair that travels with a record.
8//! [`extract_context`] and [`set_remote_parent`] rebuild that pair.
9//! - **Structured RPC payloads**: [`TraceCarrier`] is a serde-serialisable
10//! field inside an existing request envelope, so a node-to-node call needs
11//! no extra frame.
12//! - **SQL text**: [`extract_sqlcommenter`] reads the
13//! [sqlcommenter](https://google.github.io/sqlcommenter/) `/*traceparent='…'*/`
14//! comment that OpenTelemetry-instrumented database drivers already append.
15//!
16//! This crate deliberately depends on nothing but `opentelemetry`, `tracing`,
17//! `tracing-opentelemetry`, and `serde`. The OTLP exporter, its configuration,
18//! and the process-wide subscriber live in `krabka-telemetry`. That crate is
19//! unpublished, and it pulls in a web server, a CLI parser, and a profiler.
20//! None of those belong in a crate that a protocol codec links against.
21//! `krabka-telemetry` re-exports this crate as
22//! `krabka_telemetry::propagation`.
23//!
24//! This crate validates ingress from an untrusted client. See
25//! [`TraceCarrier::from_w3c`] for the exact rules, and for the reason it never
26//! keeps the raw client string.
27
28#![forbid(unsafe_code)]
29
30mod carrier;
31mod propagation;
32mod sqlcommenter;
33
34pub use self::{
35 carrier::{TraceCarrier, TraceContextError},
36 propagation::{
37 TRACEPARENT, TRACESTATE, current_trace_headers, extract_context, set_remote_parent,
38 },
39 sqlcommenter::{SqlCommenterTrace, extract_sqlcommenter},
40};