OpenTelemetry Cheat Sheet

Instrument, collect, and route traces, metrics, and logs — the vendor-neutral standard, from SDK environment to the Collector.

Observability6 sections · 35 commands
⌘K

SDK Environment

10
export OTEL_SERVICE_NAME=payment-api

Service name for all signals

export OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317

OTLP gRPC endpoint

export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://collector:4318/v1/traces

Traces to OTLP/HTTP

export OTEL_TRACES_EXPORTER=otlp

Exporter for traces

export OTEL_METRICS_EXPORTER=otlp

Exporter for metrics

export OTEL_LOGS_EXPORTER=otlp

Exporter for logs

export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.4.2

Custom resource attributes

export OTEL_TRACES_SAMPLER=parentbased_traceidratio

Sampler strategy

export OTEL_TRACES_SAMPLER_ARG=0.1

Sample 10% of traces

export OTEL_SDK_DISABLED=true

Turn off instrumentation

Collector Config

7
otelcol validate --config config.yaml

Validate the collector config

otelcol --config config.yaml

Run the collector

receivers: otlp: protocols: grpc: http:

Accept OTLP via gRPC and HTTP

processors: batch:

Batch before exporting

processors: memory_limiter: check_interval: 1s limit_mib: 512

Bound collector memory

exporters: otlphttp: endpoint: https://backend:4318

Forward to a backend

service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] exporters: [otlphttp]

Wire the pipeline together

Common Processors

4
processors: attributes: actions: - key: env value: prod action: upsert

Add a label to every signal

processors: resource: attributes: - key: service.version value: '{{sys.hostname}}' action: insert

Enrich resource attributes

processors: tail_sampling: decision_wait: 30s policies: - name: error type: status_code status_code: { status_codes: [ERROR] }

Keep error traces, sample the rest

processors: filter: error_mode: ignore traces: span: - 'attributes["http.route"] == "/healthz"'

Drop health-check spans

Instrumentation

6
npm install @opentelemetry/sdk-node

Node auto-instrumentation (SDK)

node -r @opentelemetry/auto-instrumentations-node/register server.js

Run with auto-instrumentation

pip install opentelemetry-distro opentelemetry-exporter-otlp

Python distro + OTLP exporter

opentelemetry-instrument python app.py

Wrap a Python app

export OTEL_PYTHON_TRACER_PROVIDER=none

Disable traces in Python

export OTEL_NODE_RESOURCE_DETECTORS=env,host

Which resource detectors load

Propagation & Context

4
export OTEL_PROPAGATORS=tracecontext,baggage

W3C trace context + baggage

traceparent: 00-<trace_id>-<parent_id>-01

The W3C traceparent header

baggage: user_id=42

Pass tags across services

export OTEL_PROPAGATORS=b3

Back-pressure for Zipkin/B3

Status & Health

4
curl http://localhost:13133/

Collector health check (zpages)

curl -s http://localhost:8888/metrics

Collector self-metrics

curl http://localhost:8888/metrics | grep otelcol_receiver_accepted

Signals accepted so far

curl http://localhost:8888/metrics | grep otelcol_exporter_sent

Signals exported upstream