Platform Engineering · Lesson 167

OpenTelemetry Instrumentation and Collectors

OpenTelemetry is the vendor-neutral standard for producing traces, metrics, and logs: SDKs and auto-instrumentation in each service, a wire protocol (OTLP), and the Collector, a pipeline that receives, processes, and exports telemetry. Getting it to work on one laptop is easy; running it for a platform means context that survives every hop, collectors that enrich and sample without falling over, and queues that ride out a backend outage. This lesson follows one span from the line of code that starts it to the trace view, and shows the two failures that matter most: broken traces and lost data.

Difficulty: Advanced · Know this first: Lesson 163, Lesson 160

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar splits the time from a span ending in the service to its being queryable, in seconds. It is a worked example, not a measurement. Batching and the tail-sampling wait are deliberate; the export hop grows when the backend is down.

Try it: will the queue ride out the outage?

Set the span rate through the gateway, its sending queue capacity, and how long the backend is down. Whatever does not fit in the queue is dropped.

seconds of buffer = capacity ÷ rate · dropped = max(0, rate × outage − capacity) · a persistent queue on disk can be far larger than one in memory

120seconds of buffer
3,600,000spans dropped
60%of the outage lost

Losing data: the queue fills before the backend returns

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

OpenTelemetry grows in four levels: first instrumenting a service, then propagation and the collector, then sampling and resilience, and finally running it as a platform.

Basic — Instrument one service

At the basic level you get one service producing traces.

  • Add auto-instrumentation for the language; set OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=dev.
  • Send to a local collector at http://localhost:4318 (OTLP over HTTP) or 4317 (gRPC).
  • Check spans with the collector's debug exporter before wiring a backend.

Try it: Basic

Which environment variable sets the service name every span will carry?

Now do it: Run one service with auto-instrumentation and a collector with the debug exporter, and read one span.

Intermediate — Propagation and the collector

At the intermediate level traces are whole and pass through a collector.

  • Propagators: OTEL_PROPAGATORS=tracecontext,baggage everywhere; check proxies, gateways, and message brokers carry the headers.
  • Agent collectors as a DaemonSet with k8sattributes and resourcedetection.
  • Pipelines: receivers: [otlp], processors: [memory_limiter, k8sattributes, batch], exporters: [otlp].

Try it: Intermediate

A message consumer's spans never join the producer's trace. What usually fixes it?

Now do it: Follow one request through a queue in your system and check whether the trace stays whole.

Advanced — Sampling and resilience

At the advanced level the pipeline keeps the right data and survives failures.

  • Tail sampling at a gateway, fed by the loadbalancing exporter routed by trace ID; policies for errors, latency, and a baseline percentage.
  • Persistent sending queues with the file_storage extension, sized for the outage you accept.
  • Collector self-monitoring: accepted, refused, sent, and failed counts; queue size against capacity; alerts on each.
  • Redaction of secrets and personal data in the collector, before anything leaves the cluster.

Try it: Advanced

During a 10-minute backend outage, the gateway lost 8 minutes of traces. What change addresses it?

Now do it: Compute your gateway's queue capacity in seconds at peak span rate.

Master — OpenTelemetry as a platform

At the master level OpenTelemetry is the platform's single path for telemetry.

  • The OpenTelemetry Operator injects auto-instrumentation and manages collectors as custom resources.
  • Semantic conventions and required resource attributes enforced in the collector.
  • Routing by tenant and signal to different backends; cost controls (sampling, filtering) owned by the platform.
  • Version policy for SDKs and collectors, and synthetic traces that test the pipeline continuously.

Trade-off: a central gateway gives one place for policy and is one more tier to scale and keep available; agent-only setups are simpler and cannot tail-sample across nodes.

Try it: Master

Why do many platforms put a collector between services and the vendor, even when the vendor accepts OTLP directly?

Now do it: Sketch your telemetry path and mark where you could enforce redaction and sampling today.

Go deeper

A gateway collector configuration with the pieces this lesson talks about: memory protection, tail sampling, redaction, and a persistent queue. It is valid for recent Collector releases with the contrib components.

Gateway collector

extensions:
  file_storage:
    directory: /var/lib/otelcol/queue

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 20
  attributes/redact:
    actions:
      - key: http.request.header.authorization
        action: delete
  tail_sampling:
    decision_wait: 30s
    policies:
      - name: errors
        type: status_code
        status_code: {status_codes: [ERROR]}
      - name: slow
        type: latency
        latency: {threshold_ms: 2000}
      - name: baseline
        type: probabilistic
        probabilistic: {sampling_percentage: 5}
  batch: {}

exporters:
  otlp/traces:
    endpoint: tempo-distributor.observability:4317
    sending_queue:
      enabled: true
      queue_size: 5000
      storage: file_storage
    retry_on_failure:
      enabled: true
      max_elapsed_time: 15m

service:
  extensions: [file_storage]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, attributes/redact, tail_sampling, batch]
      exporters: [otlp/traces]

By default queue_size counts requests (batches), not spans, so capacity in spans is roughly queue_size times the batch size; check your release's sending_queue options. TLS between collectors and to the backend is left out to keep the example short; production configurations need it.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. After a network change, checkout traces stopped showing the pricing service, and a pricing slowdown went unexplained for a day.

Timeline

  • Day 1A new internal proxy is placed between services, configured to forward only a list of known headers. Checkout p99 rises; its traces show a 3-second gap after the call to pricing, with no child spans.
  • Day 2An engineer searches pricing's own traces by time and finds slow root spans that start at pricing. Comparing raw headers shows traceparent missing after the proxy.
  • Day 2traceparent, tracestate, and baggage are added to the proxy's allow-list. Traces join again and show a cache miss in pricing.

What changed after

A synthetic request every minute is traced through every hop, and an alert fires when its trace has fewer services than expected.

If you remember nothing else

Design exercise

Design the OpenTelemetry pipeline for 120 services on three Kubernetes clusters, sending traces, metrics, and logs to one backend per signal.

Clarifying questions to ask

How many spans, data points, and log records per second at peak? Which languages need auto-instrumentation? What must be redacted? What outage of each backend must be survived without data loss? Who owns the collectors?

Rough sizing

Say 60,000 spans a second at peak, with tail sampling keeping errors, traces over 2 seconds, and 5 percent of the rest; backends may be down for up to 15 minutes.

Shape of the answer

The Operator injecting auto-instrumentation; an agent DaemonSet per cluster with k8sattributes and memory_limiter; a gateway tier per cluster behind the load-balancing exporter by trace ID; tail sampling, redaction, and persistent queues sized for 15 minutes; collector self-metrics with alerts; a synthetic trace per cluster every minute.

Trade-offs to name

A gateway tier adds a component to scale and a hop of latency, and makes tail sampling and central policy possible. Persistent queues need disk on the gateways. Longer decision_wait catches slow traces more completely and holds more data in memory.

Saved on this device, in this browser.
Next in this series · Lesson 168
Continuous Profiling and Flame Graphs

Find where CPU, wall time, locks, and allocations go with safe profiling that connects code to production behavior.

Go to Lesson 168 →

Or browse the full course from the Lessons index.