Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 179Observability · OpenTelemetry

How to trace requests with OpenTelemetry

"The checkout is slow" — but is it the API, the database, or the payment call? A trace follows one request through every service and shows how long each step (a span) took. OpenTelemetry is the standard: apps send spans with OTLP to the Collector, which batches them and forwards them to a backend such as Jaeger or Tempo. This how-to runs a Collector and Jaeger, adds tracing to an app without code changes, and reads the first trace.

  • 5 Lessen
  • 7 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

179.1

The quick answer

/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_mib: 400
  batch: {}
 
exporters:
  otlp/jaeger:
    endpoint: jaeger.example.com:4317
    tls:
      insecure: true
  debug:
    verbosity: basic
 
service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlp/jaeger, debug]
otelcol-contrib validate --config=/etc/otelcol-contrib/config.yaml
systemctl restart otelcol-contrib

179.2

Step by step

  1. Run a backend — Jaeger v2 in one container (UI on port 16686, OTLP on 4317/4318); see the Jaeger guide.
  2. Run the Collector (quick answer) — apps send to it, not straight to the backend: it batches, limits memory, can drop health checks, and lets you change the backend without touching apps.
  3. Instrument the app without code changes — Python example (Java: the -javaagent jar; Node.js: @opentelemetry/auto-instrumentations-node):
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
export OTEL_SERVICE_NAME=checkout-api
export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel.example.com:4318
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
opentelemetry-instrument python app.py

The agent creates spans for incoming HTTP requests, database calls and outgoing HTTP calls.

  1. Send a few requests and watch the Collector log — the debug exporter prints a line per batch of spans:
for i in $(seq 20); do curl -s -o /dev/null http://localhost:8000/checkout; done
journalctl -u otelcol-contrib -n 20
  1. Read the trace — Jaeger UI → service checkout-api → Find traces. The waterfall shows each span; the longest bar is your slow step.
  2. Connect services — every service needs instrumentation; the trace ID travels in the W3C traceparent HTTP header. Proxies and gateways must pass it on.
  3. Sample in production — keep 10 % of traces:
export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1
  1. Add context — OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod,service.version=1.4.2 so you can filter by version after a deploy.

179.3

Check that it worked

otelcol-contrib validate ends without errors; the Collector log shows spans arriving; curl -s http://jaeger.example.com:16686/api/services lists checkout-api; a trace in the UI shows the HTTP span with child spans for the database.

179.4

Common problems

ProblemCauseFix
No traces at allPort and protocol do not match (4317 = gRPC, 4318 = HTTP).Set OTEL_EXPORTER_OTLP_PROTOCOL to match the port.
Each service shows separate tracestraceparent is lost (proxy, queue, missing instrumentation).Instrument all services; let the proxy pass the header.
Collector is killed (OOM)No memory limit, big bursts.memory_limiter first in the pipeline; more memory.
Exporter connection refusedBackend address or TLS setting wrong.Check endpoint; tls.insecure only inside a private network.
Too much data / cost100 % sampling.Head sampling (ratio) or tail sampling in the Collector.
Secrets in span attributesSQL statements or headers recorded.Turn off statement capture; a processor to delete attributes.

179.5

Go further

1Why send spans to a Collector instead of straight to Jaeger?

The Collector batches and limits data, can filter it, and lets you change the backend without changing every app.

2How does one trace cross several services?

The trace ID travels in the W3C traceparent header; each instrumented service continues the same trace.

Alle commando's in dit hoofdstuk