Overview
OpenTelemetry Rust provides logging capabilities through a bridge API rather than an end-user logging API. This design allows you to continue using familiar logging libraries likelog and tracing while automatically bridging those logs to OpenTelemetry backends.
Architecture
Unlike traces and metrics, OpenTelemetry does not provide a dedicated logging API for end-users. Instead, it recommends using existing logging libraries and bridging them to OpenTelemetry logs.
Components
- Logging Library: Your application uses
logortracingcrates for emitting logs - Log Appender (Bridge): Converts logs from the logging library to OpenTelemetry
LogRecords - LogProcessor: Handles batching and processing of log records
- LogExporter: Exports logs to backends (OTLP, stdout, etc.)
Bridge API vs End-User API
The OpenTelemetry Logs Bridge API is designed for logging library authors, not application developers:Key Concepts
LogRecord
ALogRecord represents a single log event with the following key properties:
- Timestamp: When the log event occurred
- Observed Timestamp: When the log was recorded by the system
- Severity: Log level (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
- Body: The log message
- Attributes: Key-value pairs for structured logging
- Trace Context: Links logs to traces (trace ID, span ID, trace flags)
- Target: The module/component that emitted the log
- Event Name: Optional name for the log event
Severity Levels
OpenTelemetry defines 24 severity levels, but most appenders map from standard log levels:| Standard Level | OTel Severity | Severity Number |
|---|---|---|
| TRACE | Trace | 1 |
| DEBUG | Debug | 5 |
| INFO | Info | 9 |
| WARN | Warn | 13 |
| ERROR | Error | 17 |
| FATAL | Fatal | 21 |
AnyValue
Log attributes and body use theAnyValue type to support various data types:
Int(i64)- Integer valuesDouble(f64)- Floating-point valuesString(StringValue)- String valuesBoolean(bool)- Boolean valuesBytes(Vec<u8>)- Byte arraysListAny(Vec<AnyValue>)- Arrays of valuesMap(HashMap<Key, AnyValue>)- Nested maps
Available Appenders
OpenTelemetry Rust provides two official log appenders:log Appender
Bridge logs from the
log crate to OpenTelemetrytracing Appender
Bridge logs from the
tracing crate to OpenTelemetryLog Processors
Processors handle how logs are buffered and exported:- SimpleLogProcessor: Exports logs immediately (for development)
- BatchLogProcessor: Batches logs for efficient export (for production)
Trace Context Integration
One of the key benefits of using OpenTelemetry logs is automatic correlation with distributed traces. When a log is emitted within an active trace context, the log record automatically includes:- Trace ID: Links the log to a distributed trace
- Span ID: Links the log to a specific span within the trace
- Trace Flags: Indicates if the trace is sampled
Quick Start
Example
Here’s a minimal example using thetracing appender:
Next Steps
Bridge API
Learn about the core Bridge API types and traits
log Appender
Set up logging with the
log cratetracing Appender
Set up logging with the
tracing crateLog Processors
Configure batch and simple processors