OpenTelemetry is an open standard and set of tools for collecting traces, metrics, and logs from applications and services so you can send them to observability backends. For an SRE it's useful because it standardizes telemetry, reduces vendor lock-in, and lets you centralize processing/forwarding.Main components- SDKs: Language-specific libraries (opentelemetry-api + opentelemetry-sdk) that generate telemetry, provide context propagation, sampling, and batching.- Instrumentations: Libraries (automatic or manual) that hook into frameworks, DB drivers, HTTP clients, etc., to produce traces/metrics with minimal code changes.- Collector: A standalone agent/service (receivers → processors → exporters) that can receive OTLP (or other) telemetry, enrich/filter/aggregate it, and forward to one or more backends.Enabling auto-instrumentation for a Python web service1. Install packages:bash
pip install opentelemetry-api opentelemetry-sdk \
opentelemetry-instrumentation opentelemetry-exporter-otlp
2. Run your app with the auto-instrument runner:bash
opentelemetry-instrument --service-name myservice python app.py
This auto-enables supported instrumentations (Flask/Django/requests/DBs). For explicit control, install specific instrumentation packages (e.g., opentelemetry-instrumentation-flask) or initialize instrumentation in code.3. Optionally provide a small bootstrap config (environment variables or SDK code) for resources, sampling, and exporter settings.Configuration choices for exporting metrics, logs, traces- Transport & endpoint: OTLP over gRPC/HTTP — set OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS. Decide whether agents send directly to backend or via a Collector.- Use a Collector when you need local buffering, protocol translations, batching, sampling, enrichment, or to forward to multiple backends.- Sampling: configure sampler (trace percentage or parent-based) to limit high-cardinality trace volume.- Batching and retries: tune batch size, timeout and retry/backoff to avoid blocking app threads and to handle backend outages.- Security & auth: TLS, mTLS, API keys or headers — configure in exporter/collector.- Metrics specifics: choose aggregation temporality (cumulative vs delta), scrape vs push model, and histogram buckets if supported.- Resource attributes & semantic conventions: set service.name, environment, version for correct filtering/alerting.- Correlation: ensure trace IDs are attached to logs (configure log instrumentation or use Collector to correlate).- Cardinality control & attribute filtering: drop high-cardinality attributes before export (in SDK or Collector) to control cost.In practice: run opentelemetry-instrument locally pointing exporters at your Collector (OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317), tune sampling and batching in Collector config, and enable attribute filtering in the Collector to protect backend cost and performance.