Expand description
OTLP span emission (gateway L4 observability) — SDK-free tracing straight from the request path.
When [llm.telemetry] is enabled, EdgeGuard emits one OpenInference/OTLP span per metered LLM
request to an OTLP/HTTP /v1/traces receiver (e.g. evald). Because the proxy sits in the request
path, the span carries the correct model, per-tier tokens, computed cost, and server-side
TTFT/TPOT/latency with no client SDK, no import-order fragility, and no per-framework instrumentor
drift — the exact failure class that plagues in-process instrumentation (nested usage, dropped
spans, async nesting breakage). Emission is fire-and-forget: it never blocks or fails the
client response.
The wire format is OTLP-JSON posted with the crate’s existing HTTP client, so the data plane
stays a single static binary (no protobuf codegen, no OpenTelemetry SDK). The span attribute keys
are exactly the OpenInference / gen_ai.* keys a downstream store normalizes (llm.model_name,
llm.token_count.*, input.value, …), so a gateway span round-trips into evald unchanged.
Structs§
- Server
Span - One proxied HTTP request, rendered as an OpenTelemetry SERVER span.
- Span
Record - A metered LLM request rendered into span form.
input/outputstayNoneunless content capture is enabled (they are populated, already DLP-redacted, at the wiring site). - Span
Ship Stats - Counters for the span shipper. A trace pipeline that drops silently reads, at the destination, as an absence of traffic.
- Span
Shipper - Bounded queue + background task that batches server spans into OTLP-JSON POSTs.
- Telemetry
Runtime - The compiled telemetry runtime carried on the proxy
Runtime. - Trace
Context - W3C trace context for one emitted span.
parent_span_idis set when an inboundtraceparentstitched this gateway span under an app-side span (so both land in one trace).
Functions§
- build_
export_ json - Build the OTLP-JSON
ExportTraceServiceRequestfor one span. The attribute keys are the OpenInference /gen_ai.*keys a downstream OTel store normalizes, so the span round-trips. Ints are encoded as strings (the protobuf int64 → JSON mapping OTLP-JSON uses). - build_
server_ spans_ json - Build the OTLP-JSON for a batch of server spans — one POST body for many spans.
- prepare_
content - Lossy-UTF8 a captured body and truncate it to
max_byteson a char boundary (with a marker), so a large prompt/response can’t bloat the emitted span. Used at the content-capture wiring site. - spawn_
span_ shipper - Build the shipper and spawn its background task.
Nonewhen tracing is off or unconfigured. - trace_
sampled - Whether a trace id falls in the sampled fraction, as a free function so the HTTP server span and the LLM client span reach the SAME verdict for one request. Deterministic per trace: folding both 64-bit halves together is the uniform draw, so a trace is sampled consistently wherever it is evaluated and a trace is never half-recorded.
- traceparent_
header - Render a
TraceContextas the W3Ctraceparentheader value to send upstream.