DevOps Intermediate
OpenTelemetry — Unified Observability¶
OpenTelemetryObservabilityTracingMetrics 6 min read
OpenTelemetry as the standard for traces, metrics and logs. Instrumentation, Collector and backend integration.
What is OpenTelemetry¶
OpenTelemetry (OTel) is a CNCF project that unifies traces, metrics and logs into a single standard.
- API — defines the instrumentation interface
- SDK — implementation for each language
- Collector — agent for receiving, processing and exporting telemetry
- OTLP — protocol for data transmission
Auto-instrumentation¶
# Java agent
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.service.name=order-service \
-Dotel.exporter.otlp.endpoint=http://otel-collector:4317 \
-jar app.jar
Auto-instrumentation captures HTTP requests, DB queries, messaging and more without code changes.
Manual Instrumentation (Python)¶
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
provider = TracerProvider()
provider.add_span_processor(
BatchSpanProcessor(OTLPSpanExporter(endpoint="otel-collector:4317")))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("order-service")
@tracer.start_as_current_span("process_order")
def process_order(order_id: str):
span = trace.get_current_span()
span.set_attribute("order.id", order_id)
span.add_event("payment_processed")
OTel Collector¶
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
timeout: 5s
send_batch_size: 1024
exporters:
otlp/tempo:
endpoint: tempo:4317
prometheusremotewrite:
endpoint: http://prometheus:9090/api/v1/write
loki:
endpoint: http://loki:3100/loki/api/v1/push
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/tempo]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [prometheusremotewrite]
Summary¶
OpenTelemetry is the future of observability. One standard for traces, metrics and logs — vendor-neutral, with auto-instrumentation support.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.