Overview
OpenTelemetry defines three core telemetry signals that work together to provide comprehensive observability:- Traces - Track request flows through distributed systems
- Metrics - Collect numerical measurements over time
- Logs - Capture discrete events and messages
Traces
Traces track the progression of a single request as it flows through services in a distributed system. A trace is composed of one or more spans, which represent units of work.Core Concepts
Spans
A span represents a single operation within a trace. Spans form a tree structure where parent spans can have multiple child spans.Span Context
Every span has a context that includes:- Trace ID - Unique identifier for the entire trace
- Span ID - Unique identifier for this span
- Trace Flags - Sampling and other flags
- Trace State - Vendor-specific context
Working with Spans
Active Span Management
OpenTelemetry provides utilities to manage the currently active span:Simplified Span Management
Thein_span method provides a convenient way to create and manage spans:
Async Spans
For async code, useFutureExt to propagate span context:
Span Attributes, Events, and Links
Attributes
Attributes are key-value pairs that provide additional context:Events
Events represent significant points in time during a span’s lifetime:Links
Links associate a span with one or more other spans, useful for batch operations:Metrics
Metrics provide quantitative measurements about a service at runtime. Unlike traces which track individual requests, metrics aggregate data over time.Instrument Types
OpenTelemetry provides several instrument types, each optimized for different measurement patterns.Counter
Counters track values that only increase (e.g., requests served, errors):UpDownCounter
UpDownCounters track values that can increase or decrease (e.g., active connections, queue size):Histogram
Histograms measure the distribution of values (e.g., request duration, payload size):Gauge
Gauges record independent measurements that represent the current state:Observable Instruments
Observable instruments use callbacks to report values, ideal when the metric is calculated or managed elsewhere:How Metrics Work
In OpenTelemetry, raw measurements are aggregated in memory before export:- Record - Measurements are recorded with instruments
- Aggregate - Values are aggregated in memory (sum, count, min/max, histogram buckets)
- Export - Aggregated metrics are periodically exported (e.g., every 60 seconds)
Best Practices
Logs
The OpenTelemetry Logs Bridge API provides integration between existing logging libraries and OpenTelemetry. It’s designed for logging library authors, not application developers.Using Logs with Tracing
Application developers should use familiar logging libraries liketracing:
Log Attributes
Logs can include structured attributes:Instrumentation Scope
All signals can be associated with an instrumentation scope that identifies the library or component:Next Steps
Resources
Learn about resource detection and service identification
Context Propagation
Understand how to propagate context across services