opentelemetry-appender-tracing
Version: 0.31.1 Theopentelemetry-appender-tracing crate bridges tracing events to OpenTelemetry logs, allowing applications using the tracing ecosystem to export structured logs via OpenTelemetry.
This is different from
tracing-opentelemetry, which converts tracing spans into OpenTelemetry traces. This crate specifically handles tracing events as OpenTelemetry logs.Installation
Feature Flags
experimental_metadata_attributes: Include code metadata (file path, line number, module) as attributesexperimental_span_attributes: Include parent span information as attributes
Quick Start
Basic Setup
Structured Events
Core Types
A
tracing_subscriber::Layer that forwards tracing events to OpenTelemetry logsField Mapping
Howtracing events map to OpenTelemetry logs:
Event Name
tracing events can optionally have a name, which becomes the OpenTelemetry EventName:
Target
Thetarget field maps to OpenTelemetry InstrumentationScope:
Severity
tracing::Level maps to OpenTelemetry severity:
tracing::Level | Severity Text | Severity Number |
|---|---|---|
ERROR | Error | 17 |
WARN | Warn | 13 |
INFO | Info | 9 |
DEBUG | Debug | 5 |
TRACE | Trace | 1 |
Fields → Attributes
tracing event fields become OpenTelemetry attributes, except:
- Field named
"message"→LogRecord::Body - If no
"message"field exists, the event’s formatted message →LogRecord::Body
Type Conversion
tracing Type | OpenTelemetry Type | Notes |
|---|---|---|
i64 | AnyValue::Int | |
u64, u128, i128 | AnyValue::Int or String | Converted if fits in i64, else stringified |
f32, f64 | AnyValue::Double | |
bool | AnyValue::Boolean | |
&str | AnyValue::String | |
&[u8] | AnyValue::Bytes | Binary data |
&dyn Debug | AnyValue::String | Via Debug formatting |
&dyn Error | AnyValue::String | Stored in exception.message attribute |
Automatic Context Attachment
The bridge automatically attaches OpenTelemetry trace context to logs:Examples
Basic Logging
Named Events
With Explicit Message
Exception Logging
With Parent Spans
Integration with OTLP
Combining with Tracing Spans
For converting
tracing spans to OpenTelemetry traces, use the third-party tracing-opentelemetry crate. Both can be used together:tracing-opentelemetry: Spans → OpenTelemetry Tracesopentelemetry-appender-tracing: Events → OpenTelemetry Logs
Metadata Attributes (Experimental)
Withexperimental_metadata_attributes feature:
code.filepath: Source file pathcode.line_number: Line numbercode.function_name: Module path
Performance Considerations
- Events are only processed if the level is enabled
- Use
BatchLogProcessorfor better throughput - Field serialization has overhead; avoid excessive fields
- The bridge integrates as a
Layer, allowing composition with other layers
Differences from tracing-opentelemetry
| Feature | opentelemetry-appender-tracing | tracing-opentelemetry |
|---|---|---|
| Purpose | Events → OpenTelemetry Logs | Spans → OpenTelemetry Traces |
| Maintained by | OpenTelemetry project | Third-party (Tokio) |
| Event handling | Converts to logs | Converts to span events |
| Span handling | Not supported | Converts to traces |
Related Crates
- opentelemetry - Core API with Logs Bridge API
- opentelemetry-sdk - SDK with log processors
- opentelemetry-appender-log - Bridge for
logcrate - tracing - Application-level tracing for Rust
- tracing-opentelemetry - Third-party spans-to-traces bridge
Documentation
Full API Documentation
View complete API reference on docs.rs
tracing Crate
Documentation for the tracing crate