Course contents · Lesson 12 of 21

What Is the OpenTelemetry Collector? Hands-On Intro

OpenTelemetry Collector and Jaeger · Lesson 12 of 21 · 11 min Hands-on

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.

Three apps, shop-demo, payments and inventory, each with the OTel SDK, send OTLP to one OpenTelemetry Collector. Inside it, receivers take data in (otlp), processors change it (batch) and exporters send it out (otlp_grpc); an extensions strip shows health_check on port 13133, and each pipeline carries one signal type. A solid line sends traces to Jaeger, the path this lab uses; dashed lines send metrics to Prometheus and logs to a log store. OTLP is gRPC on port 4317 or HTTP on port 4318.
The apps only know the Collector's address; which backend gets each signal is decided in one config file.

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 otlp receiver listens for OTLP; others accept formats such as Zipkin, or scrape Prometheus endpoints.
  • Processors change data in transit: batch groups it, and others filter, sample, or add and remove attributes.
  • Exporters send data out. otlp_grpc sends 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.

Flowchart. Telemetry arrives as OTLP on port 4317 or 4318, the receiver decodes it into internal data, processors batch, filter or add fields, and the exporter queue holds up to 1000 batches. The exporter sends a batch to Jaeger over OTLP gRPC. Accepted: done, Jaeger stores the spans. Not accepted: if it is a temporary error and under 5 minutes of trying, wait and retry, starting at 5 seconds and growing to 30 seconds, then send again; otherwise the batch is dropped and counted as failed. Notes: when the queue is full, new data is dropped at once; permanent errors such as bad data skip the retries.
Failures are handled inside the Collector: queue, wait, retry, and only then drop.

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.

Two panels. Agent: host A and host B each run an app and its own Collector, as a sidecar or one per host, and both Collectors send to the backends; plus, simple, one Collector per app or host; minus, harder to change across many hosts. Gateway: three apps send to a load balancer in front of two shared Collectors, one pool per cluster or region, which send to the backends; plus, one place for keys and policy; minus, one more service that can fail.
An agent keeps the Collector close to each app; a gateway keeps keys and rules in one shared place.

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