Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

otelcol

The OpenTelemetry Collector receives traces, metrics and logs (OTLP and more), processes them and exports them to any backend.

Level
DevSecOps service
Group
Monitoring and logging
Needs root
For changes
Package
otelcol-contrib
Also called
otelcol-contrib, opentelemetry-collector

What it does

OpenTelemetry (CNCF) is the standard way for apps to send traces, metrics and logs. Apps use an OTel SDK or auto-instrumentation and send OTLP (gRPC 4317, HTTP 4318) to the Collector. The Collector has receivers (otlp, prometheus, filelog, hostmetrics), processors (batch, memory_limiter, attributes, filter, k8sattributes) and exporters (otlp to Tempo/Jaeger, prometheusremotewrite, loki, azuremonitor), joined in pipelines.

otelcol-contrib is the build with most components. In Kubernetes, use the OpenTelemetry Operator or the Helm chart.

How to write it

otelcol-contrib --config=FILE
otelcol-contrib validate --config=FILE

Main parts

Config sections

receivers
Where data comes in (otlp, prometheus, filelog, hostmetrics).
processors
Change data (batch, memory_limiter, attributes, filter).
exporters
Where data goes (otlp, otlphttp, prometheusremotewrite, debug).
extensions
health_check, pprof, zpages, auth.
service.pipelines
traces / metrics / logs: receivers → processors → exporters.

Options 4

Most used

Command flags

--config=FILE
Config file (can repeat; also env:, yaml: sources).
validate
Check the config and exit.
components
List built-in components.
--feature-gates=NAME
Turn on new features.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1A simple gateway config

    cat /etc/otelcol-contrib/config.yaml
    receivers:
      otlp:
        protocols:
          grpc: { endpoint: 0.0.0.0:4317 }
          http: { endpoint: 0.0.0.0:4318 }
    processors:
      memory_limiter: { check_interval: 1s, limit_percentage: 80, spike_limit_percentage: 20 }
      batch: {}
    exporters:
      otlp/tempo: { endpoint: tempo.monitoring.svc:4317, tls: { insecure: true } }
      prometheusremotewrite: { endpoint: http://prometheus.monitoring.svc:9090/api/v1/write }
      debug: { verbosity: basic }
    service:
      pipelines:
        traces:  { receivers: [otlp], processors: [memory_limiter, batch], exporters: [otlp/tempo] }
        metrics: { receivers: [otlp], processors: [memory_limiter, batch], exporters: [prometheusremotewrite] }
  2. 2Validate and start

    otelcol-contrib validate --config=/etc/otelcol-contrib/config.yaml
    systemctl restart otelcol-contrib
  3. 3Run in a container

    podman run -d --name otelcol -p 4317:4317 -p 4318:4318 -v ./config.yaml:/etc/otelcol-contrib/config.yaml:Z docker.io/otel/opentelemetry-collector-contrib:0.112.0
  4. 4Send a test trace with telemetrygen

    telemetrygen traces --otlp-insecure --otlp-endpoint localhost:4317 --traces 5
  5. 5Point an app at the collector

    export OTEL_SERVICE_NAME=shop-api
    export OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol:4318
    export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod
    opentelemetry-instrument python app.py
  6. 6Collect host metrics too

    cat hostmetrics.yaml
    receivers:
      hostmetrics:
        collection_interval: 30s
        scrapers: { cpu: {}, memory: {}, filesystem: {}, network: {} }
  7. 7Remove sensitive attributes

    cat redact.yaml
    processors:
      attributes/redact:
        actions:
          - { key: http.request.header.authorization, action: delete }
          - { key: user.email, action: hash }
  8. 8Install on Kubernetes with Helm

    helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
    helm install otel open-telemetry/opentelemetry-collector -n monitoring --set mode=daemonset --set image.repository=otel/opentelemetry-collector-contrib
  9. 9Check health

    curl -s http://localhost:13133/
  10. 10List the components of your build

    otelcol-contrib components | head -40

Watch out

  • Always put memory_limiter first and batch last in the processor list.
  • Traces can carry personal data and tokens in attributes; redact them in the collector.
  • Do not expose 4317/4318 to the internet without auth (use the auth extensions or a gateway).

Files

/etc/otelcol-contrib/config.yaml
Configuration (RPM/DEB packages).

Tips to remember

  • Agent (on each node) + gateway (central) is the common setup.

Exit codes

0Success.
1Error (invalid config).