Skip to main content

opentelemetry-appender-log

Version: 0.31.0 The opentelemetry-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 (enables serde serialization)
  • 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 OpenTelemetry

Field Mapping

This section describes how log records map to OpenTelemetry log records:

Body

The stringified message from log::Record::args() becomes the log body.

Severity

log::Level maps to OpenTelemetry severity:

Target

The log::Record::target() becomes the OpenTelemetry InstrumentationScope name.

Attributes

Key-value pairs from log::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 the experimental_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 BatchLogProcessor for better performance
  • The with-serde feature adds overhead for complex types

Integration with OTLP

Differences from Direct Logging

This bridge is designed for applications already using the log crate. If you’re starting fresh, consider using the tracing crate with opentelemetry-appender-tracing, which provides better structured logging support.

Documentation

Full API Documentation

View complete API reference on docs.rs

log Crate

Documentation for the log crate

Minimum Rust Version

MSRV: 1.75.0