Skip to main content

opentelemetry-appender-tracing

Version: 0.31.1 The opentelemetry-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 attributes
  • experimental_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 logs

Field Mapping

How tracing events map to OpenTelemetry logs:

Event Name

tracing events can optionally have a name, which becomes the OpenTelemetry EventName:

Target

The target 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 Traces
  • opentelemetry-appender-tracing: Events → OpenTelemetry Logs

Metadata Attributes (Experimental)

With experimental_metadata_attributes feature:
Automatically includes:
  • code.filepath: Source file path
  • code.line_number: Line number
  • code.function_name: Module path

Performance Considerations

  • Events are only processed if the level is enabled
  • Use BatchLogProcessor for better throughput
  • Field serialization has overhead; avoid excessive fields
  • The bridge integrates as a Layer, allowing composition with other layers

Differences from tracing-opentelemetry

Documentation

Full API Documentation

View complete API reference on docs.rs

tracing Crate

Documentation for the tracing crate

Minimum Rust Version

MSRV: 1.75.0