> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/open-telemetry/opentelemetry-rust/llms.txt
> Use this file to discover all available pages before exploring further.

# opentelemetry

> Core OpenTelemetry API for Rust providing traces, metrics, and logs interfaces

# 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.

<Note>
  This crate provides **API definitions only** (no-op implementations). To actually collect and export telemetry, you need to use [`opentelemetry-sdk`](/api/opentelemetry-sdk) along with exporters like [`opentelemetry-otlp`](/api/opentelemetry-otlp).
</Note>

## Installation

```toml theme={null}
[dependencies]
opentelemetry = "0.31"
```

### 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.

```rust theme={null}
use opentelemetry::Context;

let cx = Context::current();
```

### Tracing API

Create distributed traces to track request flows:

```rust theme={null}
use opentelemetry::{global, trace::{Tracer, Span}, KeyValue};

let tracer = global::tracer("my_service");
let mut span = tracer.start("my_span");
span.set_attribute(KeyValue::new("http.client_ip", "83.164.160.102"));
span.end();
```

### Metrics API

Record measurements about your service:

```rust theme={null}
use opentelemetry::{global, KeyValue};

let meter = global::meter("my_service");
let counter = meter.u64_counter("request.count").build();
counter.add(1, &[KeyValue::new("http.client_ip", "83.164.160.102")]);
```

### Logs Bridge API

<Warning>
  The Logs Bridge API is **not** intended for direct use by application developers. Use log appenders like [`opentelemetry-appender-log`](/api/opentelemetry-appender-log) or [`opentelemetry-appender-tracing`](/api/opentelemetry-appender-tracing) instead.
</Warning>

### Propagators API

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

```rust theme={null}
use opentelemetry::global;

let propagator = opentelemetry::propagation::TraceContextPropagator::new();
global::set_text_map_propagator(propagator);
```

## Core Types

<ParamField path="Context" type="struct">
  Carries execution-scoped values across API boundaries
</ParamField>

<ParamField path="KeyValue" type="struct">
  Key-value pair for attributes on spans, metrics, and logs
</ParamField>

<ParamField path="Value" type="enum">
  Supported attribute value types: Bool, Int, Double, String, Array
</ParamField>

### Trace Types

<ParamField path="trace::Tracer" type="trait">
  Creates and manages spans
</ParamField>

<ParamField path="trace::Span" type="trait">
  Represents a single operation within a trace
</ParamField>

<ParamField path="trace::TracerProvider" type="trait">
  Creates `Tracer` instances
</ParamField>

<ParamField path="TraceId" type="struct">
  16-byte unique identifier for a trace
</ParamField>

<ParamField path="SpanId" type="struct">
  8-byte unique identifier for a span
</ParamField>

### Metrics Types

<ParamField path="metrics::Meter" type="trait">
  Creates metric instruments
</ParamField>

<ParamField path="metrics::Counter" type="trait">
  Monotonically increasing metric
</ParamField>

<ParamField path="metrics::Histogram" type="trait">
  Records distribution of values
</ParamField>

<ParamField path="metrics::Gauge" type="trait">
  Records current value
</ParamField>

<ParamField path="metrics::UpDownCounter" type="trait">
  Counter that can increase or decrease
</ParamField>

## 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

## Related Crates

* **[opentelemetry-sdk](/api/opentelemetry-sdk)** - SDK implementation
* **[opentelemetry-otlp](/api/opentelemetry-otlp)** - OTLP exporter
* **[opentelemetry-stdout](/api/opentelemetry-stdout)** - Stdout exporter for debugging

## Documentation

<Card title="Full API Documentation" icon="book" href="https://docs.rs/opentelemetry/0.31.0">
  View complete API reference on docs.rs
</Card>

## Minimum Rust Version

**MSRV:** 1.75.0
