opentelemetry-appender-log
Version: 0.31.0 Theopentelemetry-appender-log crate provides a log appender that bridges the log crate to OpenTelemetry’s Logs Bridge API, enabling log events to be exported via OpenTelemetry.
Installation
Feature Flags
with-serde: Support complex values as attributes without stringifying (enablesserdeserialization)experimental_metadata_attributes: Include code location metadata (file path, line number, module) as attributes
Quick Start
Basic Setup
With Key-Value Attributes
Core Types
struct
Log appender that implements
log::Log trait and forwards log records to OpenTelemetryField Mapping
This section describes howlog records map to OpenTelemetry log records:
Body
The stringified message fromlog::Record::args() becomes the log body.
Severity
log::Level maps to OpenTelemetry severity:
Target
Thelog::Record::target() becomes the OpenTelemetry InstrumentationScope name.
Attributes
Key-value pairs fromlog::Record::key_values() are converted to attributes.
Type Conversion
Without with-serde Feature
With with-serde Feature
Enables rich type support using serde:
Metadata Attributes
With theexperimental_metadata_attributes feature:
Examples
Basic Logging
Structured Logging
With Custom Target
Complex Types (with serde)
Performance Considerations
- The bridge evaluates
enabled()before processing log records - Use appropriate log levels to avoid unnecessary overhead
- Consider using
BatchLogProcessorfor better performance - The
with-serdefeature adds overhead for complex types
Integration with OTLP
Differences from Direct Logging
Related Crates
- opentelemetry - Core API with Logs Bridge API
- opentelemetry-sdk - SDK with log processors
- opentelemetry-appender-tracing - Bridge for
tracingcrate - log - Logging facade for Rust
Documentation
Full API Documentation
View complete API reference on docs.rs
log Crate
Documentation for the log crate