krabka-trace-context
W3C Trace Context propagation helpers shared by Krabka's wire-protocol crates.
Part of Krabka, a Rust implementation of Apache Kafka.
Overview
This crate is the single place where a distributed trace crosses a Krabka process boundary. It holds only the propagation primitives. The OTLP exporter, its environment configuration, and the process-wide subscriber are in krabka-telemetry, which re-exports this crate as krabka_telemetry::propagation. The split lets published crates such as krabka-pgwire join a trace. Those crates do not need to link an HTTP server, a CLI parser, and a profiler.
Features
- Kafka record headers.
current_trace_headersinjects thetraceparentandtracestatepair that a record carries.extract_contextandset_remote_parentrebuild that pair. TraceCarrieris a serde-serialisable trace context. It travels inside an existing RPC payload, so a node-to-node call needs no extra frame. Useapply_toto make it the parent of a span. Uselink_intoto attach it as an OpenTelemetry link for fan-out and replay paths.extract_sqlcommenterreads the sqlcommenter/*traceparent='…'*/tag that OpenTelemetry-instrumented database drivers append to SQL. It scans genuine comment regions only, so a string literal cannot inject a tag.- Ingress validation. The crate checks a peer-supplied
traceparentagainst the W3C format and re-renders it from the parsed span context. A hostile value never reaches a span attribute or a log line.
Usage
use ;
let sql = "SELECT 1 /*traceparent='00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'*/";
let carrier = extract_sqlcommenter
.and_then
.unwrap_or_default;
let span = info_span!;
carrier.apply_to;
Documentation
License
Apache-2.0.