What Is the OpenTelemetry Collector? Hands-On Intro
Picture five services, each sending traces straight to Jaeger, each with its own retry code, backend address and API key. Then the team wants to drop noisy health-check traces, or try a second backend, and has to change and redeploy all five. The OpenTelemetry Collector exists to prevent that. This lesson explains what it is, what it is made of and where it runs, then starts the lab's Collector next to Jaeger.
What the Collector does, and why it sits in the middle
As the What Is OpenTelemetry? lesson of Monitoring Fundamentals explained, apps record telemetry with the OpenTelemetry SDK and send it as OTLP, the OpenTelemetry Protocol. The OpenTelemetry Collector is a separate program, one binary configured by one YAML file, that receives telemetry, processes it and exports it to the backends you choose.
Jaeger accepts OTLP itself, so an app could skip the Collector. On a laptop that works, and the OpenTelemetry documentation says small setups get decent results without one. With many apps, a Collector in the middle gives you one place for four jobs:
- Batching: sending spans, the timed steps a trace is made of, in groups instead of one request each, which saves network round trips and backend work.
- Retries: when the backend is down, the Collector keeps the data and sends it again, so a short outage need not lose any.
- Filtering: dropping noise such as health-check spans, or removing a field that holds personal data, before it leaves.
- Credentials: the backend's address and API key live in the Collector's config, not in every app.
It also makes the backend replaceable: apps keep sending OTLP to the same address, and moving to another backend becomes a config change. The price is one more service to run, size and watch.
Receivers, processors, exporters and extensions
A Collector is assembled from components, small parts you name in its config. Three kinds handle the data, in this order:
- Receivers take data in. The
otlpreceiver listens for OTLP; others accept formats such as Zipkin, or scrape Prometheus endpoints. - Processors change data in transit:
batchgroups it, and others filter, sample, or add and remove attributes. - Exporters send data out.
otlp_grpcsends OTLP over gRPC to anything that accepts it, here Jaeger.
A pipeline chains receivers, processors and exporters for one signal type: traces, metrics or logs. Extensions are a fourth kind that sit outside the pipelines and add abilities to the Collector itself. health_check answers a web request saying whether the Collector is ready, the kind of check Kubernetes or a load balancer, which spreads traffic across copies of a service, makes before sending traffic.
The flowchart follows one batch through those parts, including what happens when delivery fails.
Retries and the queue are on by default. A batch that fails with a temporary error is retried after about 5 seconds, then at growing gaps of up to 30 seconds, for up to 5 minutes. The queue holds up to 1000 batches; once it is full, new data is dropped. So the Collector rides out short outages, not long ones.
Here is the lab's whole config, otel-collector/config.yaml, without its comments. Each top-level key holds one kind of component, and service switches them on and wires them into pipelines. The next lesson reads it line by line.
extensions:
health_check:
endpoint: 0.0.0.0:13133
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch: {}
exporters:
otlp_grpc/jaeger:
endpoint: jaeger:4317
tls:
insecure: true
service:
extensions: [health_check]
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp_grpc/jaeger]
otlp_grpc/jaeger means "an otlp_grpc exporter named jaeger". Older configs and blog posts call this exporter otlp, a name that still works but is deprecated. The endpoints say 0.0.0.0, every network interface, because the Collector listens only on localhost by default, and inside a container localhost is the container itself, out of reach of other containers and Docker's published ports.
Core or contrib, and the OTLP ports
The project ships the Collector as several distributions: ready-made builds with different sets of components. Core (otelcol) holds the components from the main Collector repository plus a small selection of others. Contrib (otelcol-contrib) holds all the components of both the core and the contrib repositories, including vendor-specific exporters.
The lab runs contrib, image otel/opentelemetry-collector-contrib:0.166.0, so every component a lesson needs is already inside. Contrib's own README calls it a good starting point for trying configurations and recommends that production Collectors contain only the components they need, to reduce size and attack surface. Teams build such a custom distribution with ocb, the OpenTelemetry Collector Builder.
Two port numbers are worth memorising. OTLP over gRPC, a binary protocol on HTTP/2 that is common between services, uses port 4317. OTLP over plain HTTP uses port 4318, with paths such as /v1/traces, and works where gRPC is awkward, such as in a web browser. SDKs send to these ports on localhost unless told otherwise. The lab adds port 13133 for health_check.
Agent or gateway: where the Collector runs
In the agent pattern, a Collector runs next to each app: on the same host, as a sidecar container beside the app, or one per Kubernetes node. The app hands off its data quickly to a nearby address. It is simple to start with, but changing a setting means updating many Collectors.
In the gateway pattern, many apps send to a shared pool of Collectors behind a load balancer, usually one pool per cluster, data centre or region. Credentials and policies such as filtering or sampling live in one place. The cost is one more service that can fail, plus an extra network hop.
Larger setups often combine both: agents on every host forward to a gateway, which talks to the backends. The lab runs a single Collector that every app in it shares, a one-instance gateway for a small network.
Check yourself
Jaeger restarts and is down for 40 seconds while an app keeps sending traces through the Collector. Are those traces lost?
Usually not. The exporter keeps failed batches and retries them for up to 5 minutes, so they reach Jaeger once it is back. They are lost only if the queue fills up first.
Your config says endpoint: localhost:13133 for health_check. The container is Up, but curl -s localhost:13133 on your laptop prints nothing. Why?
Inside the container, localhost is the container itself, so the extension only accepts connections from inside it. Docker forwards the published port to the container's network interface, where nothing listens. Use 0.0.0.0:13133.
A vendor's exporter exists only in contrib, and your security team wants the smallest possible Collector. What do you run?
A custom distribution built with ocb, holding only the receivers, processors and exporters you use, including that vendor's. Core lacks the exporter, and contrib carries many components you would never use.
Go deeper
- Exploring the Power of Observability with OpenTelemetry Collector: the Collector's architecture and features in more depth.
- Unveiling the Power of OpenTelemetry Operator: Simplifying Observability in Kubernetes: running Collectors on Kubernetes, where the agent or gateway choice gets made.