Education › OSS Deep Dives › Stage 3: Observability for AI systems

The OpenTelemetry Collector

Receivers, processors, exporters and connectors; pipelines, distributions, agent vs gateway, and tail sampling for AI traces.

Intermediate ~35 min read Module 7 of 10

The OpenTelemetry Collector is a vendor-neutral pipeline for traces, metrics, logs and profiles: it receives telemetry in many formats, processes it, and exports it to one or more backends, so your applications only ever speak OTLP to a nearby Collector. This lesson works from open-telemetry/opentelemetry-collector and its contrib repository: the component model, how to read and write a pipeline configuration, which distribution to run, agent versus gateway deployments, and how tail sampling keeps the interesting AI-agent traces without storing all of them.

After this module you can
  • Explain receivers, processors, exporters, connectors and extensions, and how pipelines wire them
  • Write a Collector configuration with memory limiting, batching and Kubernetes metadata
  • Choose between the core, contrib, k8s and custom-built distributions
  • Design an agent plus gateway deployment and load-balance traces for tail sampling
  • Keep the Collector itself healthy and observable

The component model

The core repository's folders are the vocabulary. A receiver (receiver/) gets data in, by listening (OTLP on gRPC port 4317 and HTTP port 4318) or by pulling (the Prometheus receiver scrapes like Prometheus does). A processor (processor/) changes data in flight: limits memory, batches, adds attributes, filters, samples. An exporter (exporter/) sends data out. A connector (connector/) is an exporter for one pipeline and a receiver for another, for example turning spans into request-rate and latency metrics. Extensions (extension/) add capabilities outside the data path, such as health checks and authentication.

Components are referenced as type or type/name, so you can run two OTLP exporters as otlp_grpc/tempo and otlp_grpc/vendor. Defining a component does nothing on its own: it only runs when the service.pipelines section uses it. Each pipeline has one signal type (traces, metrics, logs) and an ordered list of processors.

Note

Component type names are moving to snake_case: otlp_grpc and otlp_http instead of otlp and otlphttp for exporters, k8s_attributes instead of k8sattributes. Older names still work as deprecated aliases, so older blog posts are not wrong, just dated.

A production-shaped configuration

Receive OTLP, protect memory, enrich, batch at the exporter, send to two backends
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_mib: 1500
    spike_limit_mib: 300
  k8s_attributes: {}

exporters:
  otlp_grpc/tempo:
    endpoint: tempo.monitoring.svc:4317
    tls:
      insecure: true
    sending_queue:
      batch:
  prometheus_remote_write:
    endpoint: http://prometheus.monitoring.svc:9090/api/v1/write

extensions:
  health_check:
    endpoint: 0.0.0.0:13133

service:
  extensions: [health_check]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, k8s_attributes]
      exporters: [otlp_grpc/tempo]
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, k8s_attributes]
      exporters: [prometheus_remote_write]
  • memory_limiter first. When the Collector nears its limit, it refuses new data so senders back off and retry, instead of the process being OOM-killed and losing everything in memory.
  • Batch at the exporter. The current docs batch through the exporter's sending_queue with a batch block; the separate batch processor still exists and appears in most older configs.
  • Retries and queues live in the exporter too, so a backend outage is absorbed by the queue rather than dropping data immediately.
  • Bind carefully. The Collector defaults to localhost; the examples use 0.0.0.0 so other pods can reach it, which is fine inside a cluster but not on a public host.

k8s_attributes looks up the pod that sent the data and adds namespace, pod, deployment and node as resource attributes, which is what lets you filter traces by service in your backend. The transform processor (OpenTelemetry Transformation Language) and filter processor rename, redact or drop data, for example stripping prompt text from spans before it leaves the cluster.

Distributions: which binary to run

The core repository holds only the framework and a handful of components; hundreds more live in opentelemetry-collector-contrib. You run a distribution, a binary built with a chosen set of components. The releases repository publishes several:

DistributionBinaryUse it when
CoreotelcolYou only need OTLP in and out plus the basics
Contribotelcol-contribExploring, or you need many receivers and exporters
Kubernetesotelcol-k8sRunning in Kubernetes with the components that setting needs
OTLPotelcol-otlpA minimal OTLP-only relay
Custombuilt with ocbProduction: only the components you use

Contrib is convenient but large, and every component you ship is attack surface and upgrade risk. The OpenTelemetry Collector Builder (ocb) reads a manifest listing the exact receivers, processors, exporters and extensions you want and compiles a small binary. Most teams end up there.

Agent and gateway, and tail sampling

Two deployment patterns combine well. An agent Collector runs next to workloads, as a DaemonSet on every node or a sidecar, receives from local apps, adds host and pod metadata, and forwards. A gateway Collector runs as a central, horizontally scaled Deployment that applies organisation-wide policy (redaction, sampling, routing) and holds the backend credentials, so apps and agents never do.

Head sampling decides at the start of a trace, cheaply but blindly. Tail sampling waits until a trace is complete, then keeps it if it matches a policy: any error, latency above a threshold, a specific attribute. For LLM agents this is the difference between keeping every slow or failed multi-step run and keeping a random 5% that is mostly successes.

OTLPforwardwhole tracessampled tracesmetricsApps, agentsOTel SDKsAgentDaemonSet, k8s attrsLoad-balancingroute by trace IDGatewaytail samplingTraces backendPrometheusmetrics
Agents next to the workloads add local metadata; a load-balancing tier routes each trace to one gateway, which tail-samples and holds the backend credentials.
Keep all errors and slow traces, plus 5% of the rest
yaml
processors:
  tail_sampling:
    decision_wait: 15s
    policies:
      - name: errors
        type: status_code
        status_code: {status_codes: [ERROR]}
      - name: slow
        type: latency
        latency: {threshold_ms: 8000}
      - name: baseline
        type: probabilistic
        probabilistic: {sampling_percentage: 5}
Watch out

Tail sampling only works if every span of a trace reaches the same Collector instance. Put a first tier of Collectors with the load_balancing exporter, routing by trace ID, in front of the tier that runs tail_sampling. Without it, each replica sees fragments and makes wrong decisions.

Operating the Collector

  • The Collector reports on itself: internal metrics (by default on port 8888) include accepted, refused and failed items per component, queue size and memory. Alert on refused and send-failed counts rising.
  • Validate before deploying: otelcol-contrib validate --config=config.yaml catches unknown components and typos.
  • Use the debug exporter with verbosity: detailed temporarily to print what is actually flowing through a pipeline.
  • Size the gateway on throughput and on tail-sampling memory: every in-flight trace is held for decision_wait.
  • For AI workloads, the GenAI semantic conventions define attributes such as gen_ai.request.model and gen_ai.usage.input_tokens; keep them and you can chart tokens and cost per model in any backend.
Hands-on practice

A local pipeline you can watch

  1. Run the contrib Collector in Docker with a config that has an otlp receiver and a debug exporter with verbosity: detailed, publishing ports 4317 and 4318.
  2. Install telemetrygen (from the contrib repo's cmd folder) and run telemetrygen traces --otlp-insecure --traces 5; watch spans print in the Collector logs.
  3. Add memory_limiter and a transform processor that sets a resource attribute env to lab; confirm it appears on every span.
  4. Add Jaeger or Tempo as a container, export to it with otlp_grpc, and find your traces in its UI.
  5. Add the tail_sampling policies from this lesson, generate traces where some have errors (telemetrygen traces --status-code Error), and check that all error traces arrive.
  6. Run otelcol-contrib validate --config=config.yaml after deliberately misspelling a component, and read the error.
Cheat sheet

The OpenTelemetry Collector — at a glance

Main things to focus on

  • Receivers in, processors change, exporters out, connectors bridge pipelines, extensions sit beside.
  • Nothing runs unless it is listed in service.pipelines.
  • memory_limiter first; batching and retry queues at the exporter.
  • Build a custom distribution with ocb for production instead of shipping all of contrib.
  • Agents add local metadata; gateways hold credentials and apply policy.
  • Tail sampling needs trace-ID load balancing so whole traces land on one instance.

Ports and endpoints

4317 / 4318OTLP over gRPC / OTLP over HTTP
13133health_check extension
8888Collector's own metrics (default)
55679zpages extension: live pipeline debugging pages

Core components

receivers: otlpAccept OTLP traces, metrics, logs
processors: memory_limiterRefuse data before running out of memory
exporters: otlp_grpc / otlp_httpSend OTLP onward (old names: otlp / otlphttp)
sending_queue: {batch: {}}Exporter-side queue and batching
exporters: debug verbosity: detailedPrint data to the log for troubleshooting

Contrib favourites

k8s_attributesAdd pod, namespace, deployment metadata
transform / filterRewrite, redact or drop with OTTL
tail_samplingDecide per complete trace using policies
load_balancingRoute spans by trace ID to a fixed Collector
span_metrics (connector)Generate RED metrics from spans
prometheus (receiver)Scrape Prometheus endpoints

CLI

otelcol-contrib --config=config.yamlRun with a config file
otelcol-contrib validate --config=config.yamlCheck a config without running
otelcol-contrib componentsList the components compiled into this binary
ocb --config=builder-config.yamlBuild a custom distribution

Common pitfalls

  • Defining a processor but forgetting to add it to the pipeline, so it silently never runs.
  • Running tail sampling on several replicas without trace-ID load balancing.
  • No memory_limiter, so a traffic spike OOM-kills the Collector and drops buffered data.
  • Shipping prompts or personal data in span attributes to a third-party backend without redaction.
  • Running the full contrib build in production and inheriting every component's vulnerabilities.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →