OpenTelemetry Cheat Sheet
Vendor-neutral observability instrumentation covering traces, metrics, logs, the Collector pipeline, and SDK setup across languages.
Node.js Auto-Instrumentation
Bootstrap traces and metrics for an app with zero manual span code.
// tracing.js — imported before any other moduleconst { NodeSDK } = require('@opentelemetry/sdk-node')const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc')const sdk = new NodeSDK({ traceExporter: new OTLPTraceExporter({ url: 'http://localhost:4317' }), instrumentations: [getNodeAutoInstrumentations()], serviceName: 'checkout-service',})sdk.start()
Manual Span Instrumentation
Wrap custom business logic in a span when auto-instrumentation isn't enough.
from opentelemetry import tracetracer = trace.get_tracer("checkout.service")def process_order(order_id: str): with tracer.start_as_current_span("process_order") as span: span.set_attribute("order.id", order_id) span.add_event("inventory_checked") try: charge_payment(order_id) except Exception as e: span.record_exception(e) span.set_status(trace.StatusCode.ERROR, str(e)) raise
Custom Metrics
Record a counter and a histogram alongside auto-collected runtime metrics.
from opentelemetry import metricsmeter = metrics.get_meter("checkout.service")orders_counter = meter.create_counter( "orders.processed", unit="1", description="Total orders processed")latency_histogram = meter.create_histogram( "order.processing.duration", unit="ms")orders_counter.add(1, {"status": "success"})latency_histogram.record(142.3, {"payment_provider": "stripe"})
OpenTelemetry Collector Pipeline
Receive OTLP data, batch/process it, and export to multiple backends.
receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 http: endpoint: 0.0.0.0:4318processors: batch: {} memory_limiter: limit_mib: 512exporters: otlp/jaeger: endpoint: jaeger-collector:4317 prometheus: endpoint: 0.0.0.0:8889service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] exporters: [otlp/jaeger] metrics: receivers: [otlp] processors: [batch] exporters: [prometheus]
Core Signals & Terms
The vocabulary of the OTel spec.
- Span- a single timed operation with attributes, events, and a parent/child relationship
- Trace- a tree of spans representing one end-to-end request across services
- Context Propagation- passing trace IDs across process/service boundaries (e.g. W3C traceparent header)
- Resource- metadata identifying the entity producing telemetry (service.name, host, k8s.pod.name)
- OTLP- OpenTelemetry Protocol, the standard wire format between SDKs, Collector, and backends
- Sampler- decides which traces to keep (e.g. ParentBased(TraceIdRatioBased) for head sampling)
Deploy the Collector as a separate service (not just SDK-to-backend direct export) as soon as you have more than one backend or language — it centralizes sampling, PII redaction, and retry/batching logic so you're not reimplementing them in every service's SDK config.
Explore Topics
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance