TExcelTAD

The OpenTelemetry Collector

The Collector is a vendor-neutral process that receives telemetry, processes it, and exports it anywhere. Applications send OTLP to a nearby Collector instead of to backends directly, so you can change backends, add sampling, scrub data or batch traffic without touching application code.

text
                 ┌───────────────── otelcol ─────────────────┐
 apps ──OTLP──▶  │ receivers ─▶ processors ─▶ exporters      │──▶ Tempo / Jaeger (traces)
 files ────────▶ │  otlp        memory_limiter  otlp_grpc    │──▶ Prometheus (metrics)
 /metrics ─────▶ │  file_log    batch           otlp_http    │──▶ Loki (logs)
                 │  prometheus  attributes      prometheus   │
                 │              transform       file, debug  │
                 │        connectors join pipelines          │
                 └───────────────────────────────────────────┘
Part Does
receivers get data in: otlp (gRPC 4317, HTTP 4318), file_log, prometheus (scrape), host_metrics, k8s_cluster, jaeger, zipkin…
processors change it in flight: memory_limiter, batch, attributes, resource, transform (OTTL), filter, k8s_attributes, tail_sampling, redaction
exporters send it out: otlp_grpc, otlp_http, prometheus (serve /metrics), prometheus_remote_write, file, debug, vendor exporters
connectors an exporter of one pipeline that is a receiver of another: span_metrics, service_graph, count, routing
extensions not in the data path: health_check, pprof, zpages, file_storage
pipelines `service.pipelines.<traces

Distributions: the core build has only the basics; otelcol-contrib (used here) has hundreds of components; vendors ship their own builds, and you can build a minimal one with the OpenTelemetry Collector Builder (ocb). Grafana Alloy embeds the same components.

Component names changed. Recent Collector releases renamed many components to snake_case: file_log (was filelog), otlp_grpc and otlp_http exporters (were otlp and otlphttp), span_metrics (spanmetrics), k8s_attributes (k8sattributes), host_metrics (hostmetrics). The old names still work in 0.164 but log a deprecation warning such as "filelog" alias is deprecated; use "file_log" instead. Most blog posts and Helm values still use the old names; this course uses the new ones.

Validating a pipeline

otelcol-contrib validate parses the config, checks every component's settings and the pipeline wiring, without starting anything:

bash · try it yourself
cat > otel.yaml <<'YML'
receivers:
  otlp:
    protocols:
      grpc: {endpoint: 0.0.0.0:4317}
      http: {endpoint: 0.0.0.0:4318}
processors:
  memory_limiter:                # first: refuse data before the process runs out of memory
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 20
  batch: {}                      # last: fewer, bigger export requests
exporters:
  otlp_grpc/tempo:
    endpoint: tempo.observability:4317
    tls: {insecure: true}
  debug: {}
service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlp_grpc/tempo]
    logs:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [debug, missing_exporter]
YML
otelcol-contrib validate --config=otel.yaml 2>&1 | sed 's/^Error: //'
echo "exit code: ${PIPESTATUS[0]}"
sed -i 's/exporters: \[debug, missing_exporter\]/exporters: [debug]/' otel.yaml
otelcol-contrib validate --config=otel.yaml && echo "valid"
service::pipelines::logs: references exporter "missing_exporter" which is not configured
exit code: 1
valid

Components are referenced as type/name (otlp_grpc/tempo), so one config can have several exporters of the same type. A component defined but not used in any pipeline is simply ignored; one used but not defined is an error. Put validate in CI for the Collector's config, like promtool check for Prometheus.

Running a pipeline

This session runs a real Collector: an OTLP/HTTP receiver, a resource processor that stamps the environment, an attributes processor that deletes a sensitive attribute and hashes another, a transform processor (OTTL, the OpenTelemetry Transformation Language) that renames spans with IDs in them, and a file exporter. curl sends two spans as OTLP/JSON; jq reads what came out:

bash · try it yourself
cat > otel.yaml <<'YML'
receivers:
  otlp:
    protocols:
      http: {endpoint: 127.0.0.1:4318}
processors:
  resource:
    attributes:
      - {key: deployment.environment.name, value: prod, action: upsert}
  attributes/scrub:
    actions:
      - {key: http.request.header.authorization, action: delete}
      - {key: enduser.id, action: hash}
  transform:
    trace_statements:
      - context: span
        statements:
          - replace_pattern(name, "^GET /[a-zA-Z0-9]{4,}
quot;, "GET /{code}") exporters: file: path: ./out.json service: telemetry: {logs: {level: error}} pipelines: traces: receivers: [otlp] processors: [resource, attributes/scrub, transform] exporters: [file] YML otelcol-contrib --config=otel.yaml >collector.log 2>&1 & for i in $(seq 100); do curl -s -o /dev/null 127.0.0.1:4318/v1/traces && break; sleep 0.2; done cat > spans.json <<'JSON' {"resourceSpans": [{ "resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "linkly"}}]}, "scopeSpans": [{"scope": {"name": "linkly/http"}, "spans": [ {"traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b7", "name": "GET /q1x9", "kind": 2, "startTimeUnixNano": "1767261600000000000", "endTimeUnixNano": "1767261600004000000", "attributes": [{"key": "http.response.status_code", "value": {"intValue": "302"}}, {"key": "enduser.id", "value": {"stringValue": "user-42"}}, {"key": "http.request.header.authorization", "value": {"stringValue": "Bearer s3cr3t"}}]}, {"traceId": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b8", "parentSpanId": "00f067aa0ba902b7", "name": "GET short:q1x9", "kind": 3, "startTimeUnixNano": "1767261600001000000", "endTimeUnixNano": "1767261600002000000", "attributes": [{"key": "db.system.name", "value": {"stringValue": "redis"}}]} ]}]}]} JSON curl -s -H 'Content-Type: application/json' --data @spans.json 127.0.0.1:4318/v1/traces; echo for i in $(seq 50); do [ -s out.json ] && break; sleep 0.2; done jq -c '.resourceSpans[] | .resource.attributes | map({(.key): .value.stringValue}) | add' out.json jq -c '.resourceSpans[].scopeSpans[].spans[] | {name, attrs: (.attributes | map({(.key): (.value.stringValue // .value.intValue)}) | add)}' out.json
{"partialSuccess":{}}
{"service.name":"linkly","deployment.environment.name":"prod"}
{"name":"GET /{code}","attrs":{"http.response.status_code":"302","enduser.id":"6d894aa3ee802549d7f340e7c1cf0d1c1cb14cd84f768d92ffaa6785337c4997"}}
{"name":"GET short:q1x9","attrs":{"db.system.name":"redis"}}
  • The resource processor added deployment.environment.name to the resource (once for all spans of a batch).
  • The authorization header is gone; the user ID is replaced by a hash (stable, so you can still count distinct users, but not read them).
  • GET /q1x9 became GET /{code}: span names with IDs in them ruin grouping in every tracing UI. The real fix is in the instrumentation (use the route), but the Collector can clean up services you can't change quickly.
  • {"partialSuccess":{}} is the OTLP/HTTP success answer.

Deployment patterns

Pattern How Use
agent a DaemonSet (or sidecar) on every node; apps send to localhost/the node IP low latency, adds k8s_attributes, host metrics, file logs
gateway a central Deployment behind a Service, scaled horizontally sampling decisions, auth to backends, one egress point
both agents forward to gateways the common production setup

Tail sampling needs all spans of a trace in one gateway instance: put a load_balancing exporter (routing by trace ID) in front of the sampling tier. The OpenTelemetry Operator for Kubernetes manages Collectors as OpenTelemetryCollector resources and can inject auto-instrumentation into pods. Monitor the Collector itself: it exposes its own metrics (otelcol_receiver_accepted_spans, otelcol_exporter_send_failed_spans, otelcol_processor_refused_spans and queue sizes) for Prometheus to scrape.

Test yourself

Why should memory_limiter come first and batch last in a pipeline's processors?

  1. Alphabetical order
  2. The limiter must refuse data before other processors spend memory; batching just before export makes requests efficient
  3. batch must run before receivers
  4. Order doesn't matter

What is a connector in the Collector?

  1. A network plugin
  2. A component that is an exporter in one pipeline and a receiver in another, e.g. span_metrics turning traces into metrics
  3. A data source in Grafana
  4. An extension

In otelcol-contrib 0.164, what happens with the old name filelog in a config?

  1. Startup fails
  2. It still works as a deprecated alias of file_log, with a warning
  3. It is silently ignored
  4. It means a different receiver