Skip to main content

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
Each signal serves a distinct purpose and is optimized for different use cases.

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

The in_span method provides a convenient way to create and manage spans:

Async Spans

For async code, use FutureExt to propagate span context:

Attributes

Attributes are key-value pairs that provide additional context:

Events

Events represent significant points in time during a span’s lifetime:
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:
The callback is automatically invoked by the SDK before each export (typically every 60 seconds).

How Metrics Work

In OpenTelemetry, raw measurements are aggregated in memory before export:
  1. Record - Measurements are recorded with instruments
  2. Aggregate - Values are aggregated in memory (sum, count, min/max, histogram buckets)
  3. Export - Aggregated metrics are periodically exported (e.g., every 60 seconds)

Best Practices

Reuse Instruments: Create instruments once and reuse them. Avoid creating new instruments for each measurement.
Clone for Sharing: Instruments are cheaply cloneable and can be shared across threads.

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 like tracing:

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