The Collector: the Seam That Makes OpenTelemetry Operationally True
Pipeline Anatomy
A Collector is a set of independent pipelines, each receivers → processors → exporters. A fourth component type, the connector, is simultaneously the exporter at the end of one pipeline and the receiver at the start of another — that is exactly how spanmetrics turns a trace pipeline into a metrics pipeline (see What It Costs). Extensions sit outside pipelines entirely (health check, pprof, file_storage).
receivers:
otlp: { protocols: { grpc: { endpoint: 0.0.0.0:4317 }, http: {} } }
processors:
memory_limiter: { check_interval: 1s, limit_mib: 1600, spike_limit_mib: 400 }
k8sattributes: { passthrough: false, filter: { node_from_env_var: KUBE_NODE_NAME } }
resourcedetection: { detectors: [env, system, eks], timeout: 2s }
filter:
error_mode: ignore
trace_conditions:
- span.attributes["url.path"] == "/healthz"
- span.attributes["url.path"] == "/metrics"
transform:
trace_statements:
- replace_pattern(span.attributes["url.full"], "(token=)[^&]+", "$$1REDACTED")
batch: { send_batch_size: 8192, timeout: 200ms, send_batch_max_size: 10000 }
exporters:
otlp/gateway:
endpoint: otel-gateway:4317
sending_queue: { enabled: true, num_consumers: 10, queue_size: 1000, storage: file_storage }
retry_on_failure: { enabled: true, initial_interval: 5s, max_interval: 30s, max_elapsed_time: 300s }
extensions:
file_storage: { directory: /var/lib/otelcol/file_storage }
service:
extensions: [file_storage]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, k8sattributes, resourcedetection, filter, transform, batch]
exporters: [otlp/gateway]The processor list is an ordered program, not a set. The docs are explicit: "the order of the processors in a pipeline determines the order of the processing operations." Three orderings are not stylistic preferences — they are correctness constraints.
| Rule | Why, mechanically | What breaks if you don't |
|---|---|---|
memory_limiter first | It refuses by returning an error to the preceding component. Only in position 1 is that component a receiver, which can backpressure its client | Anything upstream of it in the list has already allocated the data you're trying not to hold |
batch last, after any sampling | Batching after drops means you compress and ship only what survived | You pay CPU to batch spans you then discard, and batch sizes stop matching egress |
tail_sampling after k8sattributes, before batch | tail_sampling "reassembles spans into new batches, causing them to lose their original context" — and k8sattributes's default association is the connection IP of that context | Pod association silently fails; spans arrive with no k8s.pod.name and nobody notices for weeks |
Distributions: core, contrib, and Building Your Own
otelcol (core) is the minimal set. otelcol-contrib is everything — hundreds of components, every cloud vendor's exporter, every exotic receiver — and it is a fine way to prototype and a poor way to run production: you are shipping a binary whose attack surface and resident memory include dozens of components you will never configure. The OpenTelemetry Collector Builder (ocb) takes a manifest and compiles exactly your list:
dist:
name: otelcol-acme
output_path: ./_build
version: 1.0.0
receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.x.y
processors:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.x.y
exporters:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter v0.x.y
connectors:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.x.yThe official anti-patterns guidance names "wrong distribution choice" explicitly and recommends building a custom distribution to "pick and choose the components that you need." The practical benefit is not disk — it's that a trimmed binary has fewer CVEs to chase and a much more predictable memory floor, which matters because the Tail-Based Sampling part's buffer sizing is done against that floor.
Agent and Gateway — and Why You Run Both
Agent — sidecar or DaemonSet
- App exports to
localhost:4317. The process never blocks on a cross-AZ or cross-internet hop; a backend outage becomes the agent's problem, not a request-latency problem - Adds what the app cannot know about itself:
k8sattributes(pod, namespace, node, deployment — via the connection IP and a watch on the API server) andresourcedetection(EC2/EKS/GCP metadata, host arch, OS) - A config seam: change sampling, scrubbing, or destination by rolling a DaemonSet instead of rebuilding 23 services
- Failure domain: one node. Its queue fills, that node's spans drop
Gateway — a scaled Deployment
- Where anything needing a whole trace must live:
tail_sampling(see Tail-Based Sampling),spanmetrics(see What It Costs) - One egress point: one set of vendor credentials, one place to enforce a byte budget, one place to dual-export during a migration (see OpenTelemetry)
- Heavy transformation and re-batching, off the critical path
- Failure domain: everything. A gateway outage drops all telemetry org-wide, so it needs real capacity planning, HPA, and a persistent queue
The canonical anti-pattern is running one Collector. The canonical correct shape is agent → gateway, and for tail sampling it is agent → load-balancing gateway → tail-sampling gateway, which the tailsampling docs recommend splitting into two tiers "in order to have better failure isolation."
The Processors That Matter
memory_limiter— deliberate partial failure. It checks heap everycheck_interval(set it to1s; the config default is0s, i.e. unset). The hard limit islimit_mib; the soft limit islimit_mib − spike_limit_mib(spike_limit_mibdefaults to 20% of the limit). Above the soft limit it enters memory-limited mode and returns a non-permanent error to the preceding component, expecting receivers to retry and backpressure their sources. Above the hard limit it additionally forces GC. Without it, the Collector OOMs and you lose every buffered span plus whatever arrives during the restart; with it you lose some data and stay up. That is the trade, chosen on purpose. Note the documented caveat: data can consume memory before the limiter can reject it, especially for non-OTLP receivers — so size the limit below your container limit, and setGOMEMLIMITtoo.batch—send_batch_size: 8192,timeout: 200ms,send_batch_max_size: 0(unlimited).send_batch_sizeis a trigger, not a cap: exceed it and the whole accumulated batch ships, which is how people get 40 MB gRPC payloads rejected by a backend's message-size limit. If your backend has a cap, setsend_batch_max_size. Direction of travel: the exporter'ssending_queuenow has its own batching (min_size8192,flush_timeout200ms,sizer=requests|items|bytes), which batches after queueing and can size by bytes — something the processor cannot do. New pipelines should prefer it.attributes/transform(OTTL) /redaction— this is a compliance stage, not a nicety. Spans routinely carry the full URL including query string (url.full), SQL text (db.query.text), user IDs, and whatever an eager engineer stuffed intoenduser.*. The semantic conventions themselves hedge:db.query.text"SHOULD be collected by default only if there is sanitization that excludes sensitive information," and sanitization "SHOULD replace all literals with a placeholder." Do not trust that every instrumentation library in 23 services honors that.redactionis the fail-closed option —allowed_keysis an allowlist,blocked_valuesholds regexes for card numbers and tokens,hash_functionreplaces masking with a hash so you keep groupability, and withsummaryenabled it stampsredaction.masked.keys/redaction.masked.countso you can verify it ran.filter— the cheapest cost win that exists (see What It Costs). Health probes and metrics scrapes produce spans that are 100% uniform and 0% diagnostic. Do the arithmetic for one pod: a liveness probe and a readiness probe at the Kubernetes defaultperiodSeconds: 10is 12 requests/min, plus a 30s Prometheus scrape is 2 more — 14 spans/min of pure noise, per pod, forever. A busy pod at 20 rps buries that. A quiet internal service at 0.5 rps is ~32% health-check spans, and in a 23-service graph most services are quiet ones. Config as of v0.146+ is a flat OR-ed condition list per signal (trace_conditions) using the path-prefixed OTTL context (span.attributes[...]); the older nestedtraces: { span: [...] }form still works but is no longer documented. The documented warning is real: dropping a span orphans its children — filter on leaf spans (probe server spans), never on something that might be a parent.k8sattributesandresourcedetection.k8sattributesassociates by connection IP by default, then byk8s.pod.ip/k8s.pod.uidresource attributes; it addsk8s.namespace.name,k8s.pod.name,k8s.pod.uid,k8s.pod.start_time,k8s.deployment.name,k8s.node.nameby default and needsget/watch/listRBAC on pods (plus replicasets/nodes as configured). On a DaemonSet always setfilter.node_from_env_varor every agent watches every pod in the cluster. In a two-tier setup, run the agent inpassthrough: true(stamp the pod IP, make no API calls) and do the real lookup at the gateway — otherwise the gateway sees the agent's connection IP and labels everything with the agent's pod.tail_sampling. Buffers spans bytrace_id, evaluates policies when the trace looks complete, keeps or drops the whole thing. The Tail-Based Sampling part owns it. All you need here is its precondition, stated in its own README in capitals: "All spans for a given trace MUST be received by the same collector instance."
The loadbalancing Exporter — the Component That Makes Tail-Based Sampling Possible
This is the least-known load-bearing component in the project. It is an exporter that wraps N OTLP exporters and picks one by hashing a routing key — traceID by default for traces (also service, metric, resource, streamID, attributes). Every span of a trace therefore lands on the same downstream Collector, which is the hard prerequisite for both tail_sampling and the spanmetrics connector. Backends are discovered by a resolver: static, dns (re-resolves every 5s by default), k8s (watches EndpointSlices; needs RBAC), or aws_cloud_map.
Backpressure, the Queue, and What Survives a Restart
Every exporter sits behind sending_queue (enabled by default, queue_size: 1000 requests, num_consumers: 10) and retry_on_failure (initial_interval: 5s, max_interval: 30s, max_elapsed_time: 300s, multiplier 1.5), with a per-attempt timeout of 5s. When the queue is full, the default is block_on_overflow: false — new data is dropped at the enqueue step, counted as otelcol_exporter_enqueue_failed_spans.
The Metrics You Actually Watch
The Collector exposes its own telemetry on 127.0.0.1:8888/metrics. These are the four that tell you whether your traces are complete:
| Metric | Reading it |
|---|---|
otelcol_receiver_refused_spans | Spans that could not be pushed into a pipeline. Sustained non-zero is almost always memory_limiter refusing — i.e. this Collector is undersized right now |
otelcol_exporter_send_failed_spans | The backend rejected or was unreachable and retries were exhausted. Pair with otelcol_exporter_enqueue_failed_spans, which is the queue-full drop and a different problem |
otelcol_exporter_queue_size vs otelcol_exporter_queue_capacity | Both in batches (queue units), not spans. A ratio climbing toward 1 is the earliest warning you get; failures only start after it saturates |
otelcol_processor_incoming_items − otelcol_processor_outgoing_items | What a processor dropped, by attribution. Sampling and filtering appear here on purpose; anything else appearing here is a bug |
Every drop in this pipeline is silent to the application. The SDK's exporter got a
200 OKfrom the agent; the agent's exporter got a200 OKfrom the gateway. Nothing propagates back to the request that produced the span. These four Collector metrics are the only evidence that the trace you're about to debug with is incomplete — which is why a trace that "shows" a service making no downstream calls is never, by itself, proof that it made none (see Reading a Trace, Where Tracing Stops).
- Guarantees: A config seam outside every application: routing, enrichment, scrubbing, filtering, and sampling change by rolling a Collector, not 23 services. With
loadbalancingontraceID, every span of a trace reaches one downstream instance — the precondition for any whole-trace decision. Withfile_storage, an accepted batch survives a Collector restart. - Does not guarantee: Delivery.
memory_limiterrefuses, queues overflow, retries exhaust atmax_elapsed_time, and a rebalance splits in-flight traces — all without a single error reaching the application. It also does not guarantee a whole trace arrives: hashing routes what it receives, and a span that was never emitted, was filtered, or timed out in transit is simply not part of the set the sampler votes on (see Tail-Based Sampling).