trace module provides types for tracking the progression of a single request while it is handled by services that make up an application. A trace is a tree of Spans which are objects that represent the work being done by individual services or components involved in a request as it flows through a system.
Core Concepts
OpenTelemetry tracing consists of three main traits:- TracerProvider - The entry point of the API that provides access to Tracers
- Tracer - Responsible for creating Spans
- Span - Represents a single operation within a trace
Getting Started
Here’s a basic example of instrumenting an application:Trace Structure
A trace is a tree of spans. Each trace contains:- A root span - The top-level span with no parent
- Zero or more child spans - Spans that have a parent span
Synchronous vs Asynchronous Code
Synchronous Code
In synchronous code, usein_span for automatic span management:
Asynchronous Code
For async code, use theFutureExt trait to attach context to futures:
Working with the Global TracerProvider
OpenTelemetry provides a globalTracerProvider singleton:
Complete Example with OTLP
Here’s a complete example using the OTLP exporter:Next Steps
Tracers
Learn how to create and configure tracers
Spans
Understand span lifecycle, attributes, and events
Context Propagation
Propagate trace context across service boundaries
Sampling
Control which traces are recorded and exported