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
struct
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:
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
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
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