medium.com 4 min read Original Source

OpenTelemetry in 2026: The Definitive Getting-Started Guide

OpenTelemetry has won the observability instrumentation debate. In 2026, it is the CNCF project with the second-highest number of contributors (after Kubernetes itself), with SDKs for 11 programming languages, vendor support from every major observability platform, and adoption at organizations from early-stage startups to regulated enterprise. The question is no longer whether to adopt OpenTelemetry — it is how to do it efficiently and correctly.

This guide is the hands-on walkthrough you need to go from zero to a fully instrumented service with traces, metrics, and logs flowing to your observability backend. We cover the core concepts, the SDK setup for Python, Go, and JavaScript, auto-instrumentation for Kubernetes, the Collector deployment, and the backend integrations that make the data useful. Every code example is tested and production-applicable.

TL;DR

OpenTelemetry = one SDK for traces, metrics, and logs, sending to any backend via the OTel Collector. Start with auto-instrumentation (zero code changes), add manual spans for business logic, deploy the Collector as a DaemonSet, and export to your existing observability backend (Datadog, Grafana, Jaeger, or any OTLP-compatible receiver).

Core Concepts in 5 Minutes

Step 1: Auto-Instrumentation (Zero Code Changes)

For Python services

# Install the OTel auto-instrumentation package
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install  # Auto-installs instrumentation for detected frameworks

# Run your service with auto-instrumentation
OTEL_SERVICE_NAME=payments-api 
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 
OTEL_TRACES_EXPORTER=otlp 
OTEL_METRICS_EXPORTER=otlp 
OTEL_LOGS_EXPORTER=otlp 
opentelemetry-instrument python app.py

# What you get automatically (for Flask/FastAPI/Django):
# ✓ HTTP request spans with method, route, status code
# ✓ SQL query spans with query text (configurable sanitization)
# ✓ External HTTP calls with URL and status
# ✓ Exception recording with stack traces
# Install the OTel auto-instrumentation package
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install  # Auto-installs instrumentation for detected frameworks

# Run your service with auto-instrumentation
OTEL_SERVICE_NAME=payments-api 
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 
OTEL_TRACES_EXPORTER=otlp 
OTEL_METRICS_EXPORTER=otlp 
OTEL_LOGS_EXPORTER=otlp 
opentelemetry-instrument python app.py

# What you get automatically (for Flask/FastAPI/Django):
# ✓ HTTP request spans with method, route, status code
# ✓ SQL query spans with query text (configurable sanitization)
# ✓ External HTTP calls with URL and status
# ✓ Exception recording with stack traces

For Go services

package main

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
    sdktrace "go.opentelemetry.io/otel/sdk/trace"
# )

func initTracer() (func(), error) {
    exporter, err := otlptracegrpc.New(ctx,
        otlptracegrpc.WithEndpoint("otel-collector:4317"),
    )
    tp := sdktrace.NewTracerProvider(
        sdktrace.WithBatcher(exporter),
        sdktrace.WithResource(resource.NewWithAttributes(
            semconv.SchemaURL,
            semconv.ServiceNameKey.String("payments-api"),
        )),
    )
    otel.SetTracerProvider(tp)
    return tp.Shutdown, nil
# }
package main

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
    sdktrace "go.opentelemetry.io/otel/sdk/trace"
# )

func initTracer() (func(), error) {
    exporter, err := otlptracegrpc.New(ctx,
        otlptracegrpc.WithEndpoint("otel-collector:4317"),
    )
    tp := sdktrace.NewTracerProvider(
        sdktrace.WithBatcher(exporter),
        sdktrace.WithResource(resource.NewWithAttributes(
            semconv.SchemaURL,
            semconv.ServiceNameKey.String("payments-api"),
        )),
    )
    otel.SetTracerProvider(tp)
    return tp.Shutdown, nil
# }

Step 2: Kubernetes Auto-Instrumentation with the OTel Operator

The OpenTelemetry Operator eliminates the need to modify application deployments for instrumentation. It watches for Instrumentation CRDs and injects the OTel SDK into matching pods at startup via an init container.

<button data-code="# Install OTel Operator
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

# Create an Instrumentation resource
cat <

# Install OTel Operator
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

# Create an Instrumentation resource
cat << 'EOF' | kubectl apply -f -
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: otel-instrumentation
  namespace: production
spec:
  exporter:
    endpoint: http://otel-collector:4317
  propagators: [tracecontext, baggage, b3]
  sampler:
    type: parentbased_traceidratio
    argument: "0.1"  # Sample 10% of traces
  python:
    env:
    - name: OTEL_PYTHON_LOG_CORRELATION
      value: 'true'
  java:
    image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest
  nodejs:
    image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest
EOF

# Enable auto-instrumentation for a namespace
kubectl annotate namespace production 
  instrumentation.opentelemetry.io/inject-python=true

# Or annotate specific deployments:
kubectl patch deployment payments-api -p 
  '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-python":"true"}}}}}'
# Install OTel Operator
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

# Create an Instrumentation resource
cat << 'EOF' | kubectl apply -f -
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: otel-instrumentation
  namespace: production
spec:
  exporter:
    endpoint: http://otel-collector:4317
  propagators: [tracecontext, baggage, b3]
  sampler:
    type: parentbased_traceidratio
    argument: "0.1"  # Sample 10% of traces
  python:
    env:
    - name: OTEL_PYTHON_LOG_CORRELATION
      value: 'true'
  java:
    image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest
  nodejs:
    image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest
EOF

# Enable auto-instrumentation for a namespace
kubectl annotate namespace production 
  instrumentation.opentelemetry.io/inject-python=true

# Or annotate specific deployments:
kubectl patch deployment payments-api -p 
  '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-python":"true"}}}}}'

Step 3: Manual Instrumentation for Business Logic

Auto-instrumentation captures HTTP requests, database queries, and external calls automatically. Manual instrumentation adds spans for the business logic inside those requests — where the actual complexity and latency often lives.

Order:
with tracer.start_as_current_span("process_order") as span:
span.set_attribute("order.id", order_id)
span.set_attribute("order.source", "api"# )

# This creates a child span automatically
inventory = check_inventory(order_id)

span.set_attribute("inventory.available", inventory.available)

if not inventory.available:
span.set_status(trace.StatusCode.ERROR, "Out of stock"# )
span.record_exception(OutOfStockError(order_id))
raise OutOfStockError(order_id)

return fulfill_order(order_id)” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

from opentelemetry import trace

tracer = trace.get_tracer(__name__)

def process_order(order_id: str) -> Order:
    with tracer.start_as_current_span("process_order") as span:
        span.set_attribute("order.id", order_id)
        span.set_attribute("order.source", "api"# )

        # This creates a child span automatically
        inventory = check_inventory(order_id)

        span.set_attribute("inventory.available", inventory.available)

        if not inventory.available:
            span.set_status(trace.StatusCode.ERROR, "Out of stock"# )
            span.record_exception(OutOfStockError(order_id))
            raise OutOfStockError(order_id)

        return fulfill_order(order_id)
from opentelemetry import trace

tracer = trace.get_tracer(__name__)

def process_order(order_id: str) -> Order:
    with tracer.start_as_current_span("process_order") as span:
        span.set_attribute("order.id", order_id)
        span.set_attribute("order.source", "api"# )

        # This creates a child span automatically
        inventory = check_inventory(order_id)

        span.set_attribute("inventory.available", inventory.available)

        if not inventory.available:
            span.set_status(trace.StatusCode.ERROR, "Out of stock"# )
            span.record_exception(OutOfStockError(order_id))
            raise OutOfStockError(order_id)

        return fulfill_order(order_id)

Step 4: Deploying the OTel Collector

The OTel Collector is the central routing layer: your services send telemetry to it, and it processes and forwards to one or more backends. The most common deployment on Kubernetes: a DaemonSet for collecting from every node, plus a central Deployment for pipeline processing.

# otel-collector-config.yaml
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
  name: otel-daemonset
  namespace: observability
spec:
  mode: daemonset  # Run on every node
  config: |
    receivers:
      otlp:
        protocols:
          grpc: { endpoint: 0.0.0.0:4317 }
          http: { endpoint: 0.0.0.0:4318 }
      prometheus:
        config:
          scrape_configs:
          - job_name: 'kubernetes-pods'
            kubernetes_sd_configs:
            - role: pod

    processors:
      batch:
        timeout: 10s
        send_batch_size: 1024
      memory_limiter:
        limit_mib: 400
      k8sattributes:  # Enrich with K8s metadata
        auth_type: serviceAccount
        passthrough: false

    exporters:
      otlp:
        endpoint: grafana-agent:4317
      datadog:
        api:
          key: ${env:DD_API_KEY}

    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [memory_limiter, k8sattributes, batch]
          exporters: [otlp, datadog]
        metrics:
          receivers: [otlp, prometheus]
          processors: [memory_limiter, batch]
          exporters: [otlp]
# otel-collector-config.yaml
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
  name: otel-daemonset
  namespace: observability
spec:
  mode: daemonset  # Run on every node
  config: |
    receivers:
      otlp:
        protocols:
          grpc: { endpoint: 0.0.0.0:4317 }
          http: { endpoint: 0.0.0.0:4318 }
      prometheus:
        config:
          scrape_configs:
          - job_name: 'kubernetes-pods'
            kubernetes_sd_configs:
            - role: pod

    processors:
      batch:
        timeout: 10s
        send_batch_size: 1024
      memory_limiter:
        limit_mib: 400
      k8sattributes:  # Enrich with K8s metadata
        auth_type: serviceAccount
        passthrough: false

    exporters:
      otlp:
        endpoint: grafana-agent:4317
      datadog:
        api:
          key: ${env:DD_API_KEY}

    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: [memory_limiter, k8sattributes, batch]
          exporters: [otlp, datadog]
        metrics:
          receivers: [otlp, prometheus]
          processors: [memory_limiter, batch]
          exporters: [otlp]

Step 5: Adding Custom Metrics

from opentelemetry import metrics

meter = metrics.get_meter(__name__)

# Counter — things that only increase
order_counter = meter.create_counter(
    name="orders.processed",
    description="Total orders processed",
    unit="{orders}",
# )

# Histogram — for latency and size distributions
processing_duration = meter.create_histogram(
    name="order.processing.duration",
    description="Time to process an order",
    unit="ms",
# )

# Usage
order_counter.add(1, {"payment.method": "card", "region": "eu-west-1"})
processing_duration.record(142.5, {"order.type": "express"})
from opentelemetry import metrics

meter = metrics.get_meter(__name__)

# Counter — things that only increase
order_counter = meter.create_counter(
    name="orders.processed",
    description="Total orders processed",
    unit="{orders}",
# )

# Histogram — for latency and size distributions
processing_duration = meter.create_histogram(
    name="order.processing.duration",
    description="Time to process an order",
    unit="ms",
# )

# Usage
order_counter.add(1, {"payment.method": "card", "region": "eu-west-1"})
processing_duration.record(142.5, {"order.type": "express"})

Backend Integrations

Production Checklist

  • Sampling strategy: never sample 100% in production for high-volume services — start with 10% and tune upward for error traces (always sample errors)
  • Context propagation: ensure all services propagate the W3C TraceContext header (tracecontext propagator) to maintain trace continuity across service boundaries
  • Collector resource limits: set memory_limiter in the Collector to prevent OOM; batch processor reduces backend API calls significantly
  • Kubernetes metadata enrichment: k8sattributes processor enriches every span with pod, namespace, deployment, and node metadata
  • Secret management: never hardcode API keys in Collector config — use Kubernetes Secrets and environment variable substitution
  • Cardinality control: high-cardinality attributes (user IDs, request IDs as metric labels) will explode your metric storage — use trace attributes for high-cardinality, not metric labels

STARTING POINT

Install the OTel Operator in your cluster, create an Instrumentation CRD, and annotate one namespace. You will have distributed traces flowing without modifying a single line of application code. After that first win, add the Collector DaemonSet and point it at your existing observability backend. The entire setup takes less than 2 hours for a team with Kubernetes access.