The OpenTelemetry Collector is a vendor-neutral pipeline for traces, metrics, logs and profiles: it receives telemetry in many formats, processes it, and exports it to one or more backends, so your applications only ever speak OTLP to a nearby Collector. This lesson works from open-telemetry/opentelemetry-collector and its contrib repository: the component model, how to read and write a pipeline configuration, which distribution to run, agent versus gateway deployments, and how tail sampling keeps the interesting AI-agent traces without storing all of them.
- Explain receivers, processors, exporters, connectors and extensions, and how pipelines wire them
- Write a Collector configuration with memory limiting, batching and Kubernetes metadata
- Choose between the core, contrib, k8s and custom-built distributions
- Design an agent plus gateway deployment and load-balance traces for tail sampling
- Keep the Collector itself healthy and observable
The component model
The core repository's folders are the vocabulary. A receiver (receiver/) gets data in, by listening (OTLP on gRPC port 4317 and HTTP port 4318) or by pulling (the Prometheus receiver scrapes like Prometheus does). A processor (processor/) changes data in flight: limits memory, batches, adds attributes, filters, samples. An exporter (exporter/) sends data out. A connector (connector/) is an exporter for one pipeline and a receiver for another, for example turning spans into request-rate and latency metrics. Extensions (extension/) add capabilities outside the data path, such as health checks and authentication.
Components are referenced as type or type/name, so you can run two OTLP exporters as otlp_grpc/tempo and otlp_grpc/vendor. Defining a component does nothing on its own: it only runs when the service.pipelines section uses it. Each pipeline has one signal type (traces, metrics, logs) and an ordered list of processors.
Component type names are moving to snake_case: otlp_grpc and otlp_http instead of otlp and otlphttp for exporters, k8s_attributes instead of k8sattributes. Older names still work as deprecated aliases, so older blog posts are not wrong, just dated.
A production-shaped configuration
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 1500
spike_limit_mib: 300
k8s_attributes: {}
exporters:
otlp_grpc/tempo:
endpoint: tempo.monitoring.svc:4317
tls:
insecure: true
sending_queue:
batch:
prometheus_remote_write:
endpoint: http://prometheus.monitoring.svc:9090/api/v1/write
extensions:
health_check:
endpoint: 0.0.0.0:13133
service:
extensions: [health_check]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, k8s_attributes]
exporters: [otlp_grpc/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, k8s_attributes]
exporters: [prometheus_remote_write]- memory_limiter first. When the Collector nears its limit, it refuses new data so senders back off and retry, instead of the process being OOM-killed and losing everything in memory.
- Batch at the exporter. The current docs batch through the exporter's
sending_queuewith abatchblock; the separatebatchprocessor still exists and appears in most older configs. - Retries and queues live in the exporter too, so a backend outage is absorbed by the queue rather than dropping data immediately.
- Bind carefully. The Collector defaults to
localhost; the examples use0.0.0.0so other pods can reach it, which is fine inside a cluster but not on a public host.
k8s_attributes looks up the pod that sent the data and adds namespace, pod, deployment and node as resource attributes, which is what lets you filter traces by service in your backend. The transform processor (OpenTelemetry Transformation Language) and filter processor rename, redact or drop data, for example stripping prompt text from spans before it leaves the cluster.
Distributions: which binary to run
The core repository holds only the framework and a handful of components; hundreds more live in opentelemetry-collector-contrib. You run a distribution, a binary built with a chosen set of components. The releases repository publishes several:
| Distribution | Binary | Use it when |
|---|---|---|
| Core | otelcol | You only need OTLP in and out plus the basics |
| Contrib | otelcol-contrib | Exploring, or you need many receivers and exporters |
| Kubernetes | otelcol-k8s | Running in Kubernetes with the components that setting needs |
| OTLP | otelcol-otlp | A minimal OTLP-only relay |
| Custom | built with ocb | Production: only the components you use |
Contrib is convenient but large, and every component you ship is attack surface and upgrade risk. The OpenTelemetry Collector Builder (ocb) reads a manifest listing the exact receivers, processors, exporters and extensions you want and compiles a small binary. Most teams end up there.
Agent and gateway, and tail sampling
Two deployment patterns combine well. An agent Collector runs next to workloads, as a DaemonSet on every node or a sidecar, receives from local apps, adds host and pod metadata, and forwards. A gateway Collector runs as a central, horizontally scaled Deployment that applies organisation-wide policy (redaction, sampling, routing) and holds the backend credentials, so apps and agents never do.
Head sampling decides at the start of a trace, cheaply but blindly. Tail sampling waits until a trace is complete, then keeps it if it matches a policy: any error, latency above a threshold, a specific attribute. For LLM agents this is the difference between keeping every slow or failed multi-step run and keeping a random 5% that is mostly successes.
processors:
tail_sampling:
decision_wait: 15s
policies:
- name: errors
type: status_code
status_code: {status_codes: [ERROR]}
- name: slow
type: latency
latency: {threshold_ms: 8000}
- name: baseline
type: probabilistic
probabilistic: {sampling_percentage: 5}Tail sampling only works if every span of a trace reaches the same Collector instance. Put a first tier of Collectors with the load_balancing exporter, routing by trace ID, in front of the tier that runs tail_sampling. Without it, each replica sees fragments and makes wrong decisions.
Operating the Collector
- The Collector reports on itself: internal metrics (by default on port 8888) include accepted, refused and failed items per component, queue size and memory. Alert on refused and send-failed counts rising.
- Validate before deploying:
otelcol-contrib validate --config=config.yamlcatches unknown components and typos. - Use the
debugexporter withverbosity: detailedtemporarily to print what is actually flowing through a pipeline. - Size the gateway on throughput and on tail-sampling memory: every in-flight trace is held for
decision_wait. - For AI workloads, the GenAI semantic conventions define attributes such as
gen_ai.request.modelandgen_ai.usage.input_tokens; keep them and you can chart tokens and cost per model in any backend.