Lesson 3 of 13 · 22m
OpenTelemetry: Spans, Propagation, and the Collector
Tracing is a wire format, not a vendor — traceparent headers, span kinds, resource attributes, and why the collector owns sampling and redaction.
The wrong mental model is that tracing is a feature you buy. Tracing is a wire format plus context propagation. traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01 is a W3C header any service can read — version, trace ID, parent span ID, flags. OpenTelemetry is the vendor-neutral SDK and collector that produces and routes it; Tempo, Jaeger, Honeycomb, Datadog, and Zipkin all speak the same span language. Switching backends is an exporter line, not a rewrite.
What a span actually is
A trace is a tree of spans. Each span carries an operation name (POST /checkout), a trace ID, a span ID, a parent span ID, start and end timestamps, attributes (http.request.method, db.system, server.address), and a status. Span kinds matter at analysis time: SERVER spans are entry points, CLIENT spans are outbound calls. A CLIENT span with a 700ms duration nested inside a SERVER span is how "the database ate the request" becomes visible instead of suspected.
Context propagation is the whole trick. Service A injects traceparent into the outbound HTTP headers; service B's SERVER span adopts it as its parent. Queues do the same through message metadata — a worker consuming a Kafka record starts a span whose parent is the producer's. Break propagation and your distributed trace is twenty disconnected spans with a shared story nobody can read.
Every span also carries resource attributes — service.name, service.version, deployment.environment — stamped once at startup. These are what let you ask "did the error rate jump only on v2.4.1" across thousands of traces; skip them and every trace is anonymous.
Two smaller mechanics worth knowing: tracestate rides next to traceparent and lets vendors stash their own keys in propagation (it is how vendor-specific sampling decisions survive a hop), and span events — timestamped annotations inside a span — are where you hang "retried", "cache miss", "fallback served" without minting child spans.
The SDK and the Collector are different things
The SDK lives in your process: it creates spans and exports OTLP. The Collector is a separate service — receivers ingest OTLP (gRPC on :4317, HTTP on :4318), processors batch, sample, and enrich, exporters ship to your backend:
receivers: {otlp: {protocols: {grpc: {}, http: {}}}}
processors:
batch: {}
tail_sampling:
decision_wait: 10s
policies:
- {name: errors, type: status_code, status_code: {status_codes: [ERROR]}}
- {name: baseline, type: probabilistic, probabilistic: {sampling_percentage: 2}}
exporters: {otlp: {endpoint: tempo:4317, tls: {insecure: true}}}
service: {pipelines: {traces: {receivers: [otlp], processors: [batch, tail_sampling], exporters: [otlp]}}}The pattern that works: apps export to a local collector, the collector batches and routes. Pointing a thousand services directly at a vendor endpoint means your redaction and sampling rules are distributed across a thousand configs, and your negotiating leverage with the vendor's bill lives nowhere.
Auto-instrumentation covers HTTP frameworks, DB clients, and gRPC out of the box — the Java agent, Python's opentelemetry-instrument, Node's auto-instrumentation packages. What it cannot cover is your business logic. tracer.Start(ctx, "fraud-check") around the thing that actually eats time is the span that makes the trace worth opening.
Sampling honestly
Head sampling decides at trace start — cheap, but a 1% policy drops 99% of errors with everything else. Tail sampling waits for the complete trace (decision_wait — buffering RAM in the collector), then keeps every status_code=ERROR trace and a small percentage of the baseline. The trade is real: buffering costs memory and adds seconds of latency to visibility. It is still the standard production setup, because "we sampled away the one error trace that mattered" is a sentence nobody wants in a postmortem.
Concrete practice
- Instrument the framework automatically; instrument the business operation by hand.
trace_idin every log line; exemplars on latency histograms.- One collector per cluster — redaction, sampling, and dual-export live there.
- Baggage propagates to every downstream service. Keep it small or delete it.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.