The OpenTelemetry Collector
The OpenTelemetry Collector is a program that sits between your programs and your backends. Programs send it OTLP, and it sends their telemetry on: to one backend or several, each in its own protocol, after filtering or enriching it as its configuration says. Your programs need to know only its address, so changing backends, or the credentials they need, means changing the Collector’s configuration and nothing else.
Run it
Section titled “Run it”The files are in the repository’s examples/backends/collector/; run docker compose up -d there.
# The OpenTelemetry Collector, taking OTLP on 4318 (HTTP) and 4317 (gRPC)# and doing with it what collector.yaml says.services: collector: image: otel/opentelemetry-collector-contrib:0.161.0 volumes: - ./collector.yaml:/etc/otelcol-contrib/config.yaml:ro ports: - "4318:4318" - "4317:4317" - "13133:13133"The configuration takes OTLP over HTTP and gRPC, and prints what arrives:
# Takes OTLP from your programs, and prints what arrives. To pass it on to# a backend as well, add the backend's exporter, such as the `otlphttp` one# below, and list it in each pipeline's exporters.extensions: health_check: endpoint: 0.0.0.0:13133
receivers: otlp: protocols: http: endpoint: 0.0.0.0:4318 grpc: endpoint: 0.0.0.0:4317
exporters: debug: verbosity: detailed # otlphttp: # endpoint: https://otlp.example.com # headers: # Authorization: Bearer ${env:BACKEND_TOKEN}
service: extensions: [health_check] pipelines: traces: receivers: [otlp] exporters: [debug] metrics: receivers: [otlp] exporters: [debug] logs: receivers: [otlp] exporters: [debug]Send to it
Section titled “Send to it”Set these where your program runs, then start it:
export OTEL_SERVICE_NAME=workerexport OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318docker compose logs -f collector shows each span, metric and log record as it arrives, with every attribute.
Sending it on
Section titled “Sending it on”To send to a backend, add the backend’s exporter to exporters, and list it in each pipeline that should use it. Most backends take OTLP, which the otlphttp exporter in the comments sends: give it the backend’s endpoint and the headers it asks for. The contrib image used here has exporters for most others too.
- Keep credentials in the Collector. A header written as
${env:BACKEND_TOKEN}is read from the Collector’s environment, so the key isn’t in the file, and isn’t in any of your programs. - In Kubernetes, a Collector usually runs on each node or as a service, and programs send to its address, such as
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318. - What else it does: batching, retries and queueing on its side; dropping or renaming attributes; sampling whole traces once they’re complete. The Collector’s documentation covers each.
How it’s checked
Section titled “How it’s checked”On every change, CI starts this stack, runs the background worker with these settings, and looks for its job spans, its jobs.processed metric and its failed job’s log record in what the Collector printed. check.sh, beside the compose file, has the checks. The conformance tests check much more against a Collector: that every field arrives intact, over each protocol.