Skip to main content

Module opentelemetry

Module opentelemetry 

Source
Expand description

Distributed tracing via OpenTelemetry (opentelemetry).

The featherbit port of Apache APISIX’s opentelemetry plugin. Unlike the single-phase APISIX plugin, this is a start/end node pair wired around the upstream node, using the shared trace helper to carry a SpanContext through context.message:

  • start node (phase: start, placed right after listener, before upstream): extracts the W3C traceparent header. If present, this hop continues the incoming trace (same trace_id, the caller’s span becomes our parent, and the incoming sampled flag is honored). If absent, a new trace is started (new_trace_id(), no parent, sampled per the sampler config). Either way this hop gets a fresh span_id and start time, the span is stored via store_span, and the outgoing traceparent header is injected so the upstream service continues the trace.
  • end node (phase: end, placed after upstream, right before client): loads the span, computes its duration, and — when sampled — builds an OTLP/HTTP JSON payload and fire-and-forgets a POST to the collector’s /v1/traces endpoint on a detached tokio::spawn task (the same best-effort pattern as proxy-mirror). The export result is ignored and never blocks or fails the request.

Both nodes always return Ok: tracing is observability, so it never short-circuits the request through an error port. If the end node finds no stored span (start node absent or misordered) it passes through untouched.

§Deviations from APISIX

  • Spans are exported one-per-request (fire-and-forget) rather than through a batch span processor; batch_span_processor config is not supported.
  • Sampler strategies are always_on, always_off, and trace_id_ratio (parent_base is not supported). The new-trace sampling draw is a pseudo-random, per-trace-consistent hash of the trace id (no rand crate), so a given trace id always samples the same way in a process.
  • OTLP/JSON id fields (traceId, spanId, parentSpanId) are emitted as lowercase hex strings, which is the canonical OTLP/JSON encoding accepted by modern collectors.

Structs§

OpenTelemetryPlugin
One node of the OpenTelemetry tracing pair.

Enums§

Phase 🔒
Which node of the tracing pair this instance is.
Sampler 🔒
New-trace sampling strategy (used only when no incoming traceparent).

Functions§

build_otlp 🔒
Builds the OTLP/HTTP JSON payload for a finished span (pure; no I/O).
int_attr 🔒
parse_sampler 🔒
Parses the sampler config object into a Sampler, failing fast on an unknown strategy name or a malformed fraction.
ratio_draw 🔒
A pseudo-random draw in [0.0, 1.0) derived deterministically from a trace id, so the same trace id always samples the same way within a process. Not cryptographic; good enough for ratio sampling without a rand crate.
str_attr 🔒