Skip to main content

opentelemetry

Version: 0.31.0 The opentelemetry crate is the core API for OpenTelemetry in Rust. It provides the foundational interfaces and types for instrumenting applications with telemetry data, including traces, metrics, and logs.
This crate provides API definitions only (no-op implementations). To actually collect and export telemetry, you need to use opentelemetry-sdk along with exporters like opentelemetry-otlp.

Installation

Feature Flags

  • trace: Includes the trace API (enabled by default)
  • metrics: Includes the metrics API (enabled by default)
  • logs: Includes the logs bridge API (enabled by default)
  • internal-logs: Enables internal logging via tracing (enabled by default)

What’s Included

Context API

Manage and propagate execution context across async boundaries.

Tracing API

Create distributed traces to track request flows:

Metrics API

Record measurements about your service:

Logs Bridge API

The Logs Bridge API is not intended for direct use by application developers. Use log appenders like opentelemetry-appender-log or opentelemetry-appender-tracing instead.

Propagators API

Share context across service boundaries using propagation standards like W3C Trace Context and Baggage.

Core Types

struct
Carries execution-scoped values across API boundaries
struct
Key-value pair for attributes on spans, metrics, and logs
enum
Supported attribute value types: Bool, Int, Double, String, Array

Trace Types

trait
Creates and manages spans
trait
Represents a single operation within a trace
trait
Creates Tracer instances
struct
16-byte unique identifier for a trace
struct
8-byte unique identifier for a span

Metrics Types

trait
Creates metric instruments
trait
Monotonically increasing metric
trait
Records distribution of values
trait
Records current value
trait
Counter that can increase or decrease

Modules

  • global - Global API for tracer, meter, and propagator registration
  • trace - Distributed tracing API
  • metrics - Metrics recording API
  • logs - Logs bridge API
  • context - Context management
  • baggage - Cross-cutting concerns propagation
  • propagation - Context propagation formats

Documentation

Full API Documentation

View complete API reference on docs.rs

Minimum Rust Version

MSRV: 1.75.0