Stage 6 · Operate
Logs & Traces
OpenTelemetry Instrumentation
Using SDKs, auto-instrumentation, resource attributes, propagators, and the OpenTelemetry Collector.
OpenTelemetry Overview
OpenTelemetry (OTel) is a vendor-neutral standard for collecting telemetry data. It provides SDKs for metrics, logs, and traces in multiple languages. OTel replaces vendor-specific instrumentation with a single, portable API.
| Signal | OTel API | Export Format |
|---|---|---|
| Metrics | Meter API | OTLP |
| Traces | Tracer API | OTLP |
| Logs | Logger API | OTLP |
SDK Setup
The OTel SDK configures the API with exporters, processors, and resource information. Each language has its own SDK package. The setup pattern is consistent: create a resource, configure exporters, and initialize the SDK.
Resource Attributes
Resource attributes describe the entity producing telemetry. They include service name, version, environment, and deployment details. These attributes are attached to every span, metric, and log from the service.
OTel defines semantic conventions for standard attribute names. Use service.name, service.version, and deployment.environment instead of custom names. This ensures consistency across services and backends.
Auto-Instrumentation
Auto-instrumentation adds tracing and metrics to your application without code changes. Language-specific agents hook into libraries and frameworks automatically. This gives you immediate visibility with minimal effort.
# Download the Java agent
wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
# Run with the agent
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.service.name=my-service \
-Dotel.exporter.otlp.endpoint=http://otel-collector:4317 \
-jar my-service.jarContext Propagators
Propagators serialize and deserialize trace context across service boundaries. W3C TraceContext is the default and recommended format. It uses the traceparent header to carry trace ID and span ID between services.
# Header format
traceparent: 00-abc123def456789-a1b2c3d4e5f6-01
# Components:
# 00 - version
# abc123def456789 - trace ID
# a1b2c3d4e5f6 - parent span ID
# 01 - trace flags (sampled)Collector Role
The OTel Collector sits between your application and backends. It receives telemetry, processes it (batching, filtering, enrichment), and exports it to one or more backends. The Collector decouples your application from backend-specific configuration.
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
timeout: 5s
send_batch_size: 1000
exporters:
otlp:
endpoint: tempo:4317
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp]Never export directly from your application to backends. The Collector provides buffering, retry, and routing without changing application code. It is the recommended deployment pattern for production.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.