OpenTelemetry Cheat Sheet
Instrument, collect, and route traces, metrics, and logs — the vendor-neutral standard, from SDK environment to the Collector.
SDK Environment
10export OTEL_SERVICE_NAME=payment-apiService name for all signals
export OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317OTLP gRPC endpoint
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://collector:4318/v1/tracesTraces to OTLP/HTTP
export OTEL_TRACES_EXPORTER=otlpExporter for traces
export OTEL_METRICS_EXPORTER=otlpExporter for metrics
export OTEL_LOGS_EXPORTER=otlpExporter for logs
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.4.2Custom resource attributes
export OTEL_TRACES_SAMPLER=parentbased_traceidratioSampler strategy
export OTEL_TRACES_SAMPLER_ARG=0.1Sample 10% of traces
export OTEL_SDK_DISABLED=trueTurn off instrumentation
Collector Config
7otelcol validate --config config.yamlValidate the collector config
otelcol --config config.yamlRun 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: 512Bound collector memory
exporters:
otlphttp:
endpoint: https://backend:4318Forward to a backend
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp]Wire the pipeline together
Common Processors
4processors:
attributes:
actions:
- key: env
value: prod
action: upsertAdd a label to every signal
processors:
resource:
attributes:
- key: service.version
value: '{{sys.hostname}}'
action: insertEnrich 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
6npm install @opentelemetry/sdk-nodeNode auto-instrumentation (SDK)
node -r @opentelemetry/auto-instrumentations-node/register server.jsRun with auto-instrumentation
pip install opentelemetry-distro opentelemetry-exporter-otlpPython distro + OTLP exporter
opentelemetry-instrument python app.pyWrap a Python app
export OTEL_PYTHON_TRACER_PROVIDER=noneDisable traces in Python
export OTEL_NODE_RESOURCE_DETECTORS=env,hostWhich resource detectors load
Propagation & Context
4export OTEL_PROPAGATORS=tracecontext,baggageW3C trace context + baggage
traceparent: 00-<trace_id>-<parent_id>-01The W3C traceparent header
baggage: user_id=42Pass tags across services
export OTEL_PROPAGATORS=b3Back-pressure for Zipkin/B3
Status & Health
4curl http://localhost:13133/Collector health check (zpages)
curl -s http://localhost:8888/metricsCollector self-metrics
curl http://localhost:8888/metrics | grep otelcol_receiver_acceptedSignals accepted so far
curl http://localhost:8888/metrics | grep otelcol_exporter_sentSignals exported upstream