Overview
The OpenTelemetry Logs Bridge API provides the foundation for connecting existing logging libraries to OpenTelemetry. This API is not intended for direct use by application developers—instead, it’s designed for logging library authors to build log appenders.Core Traits
The Bridge API defines three main traits in theopentelemetry::logs module:
Logger
TheLogger trait provides methods to create and emit log records:
create_log_record()- Creates a new log record that can be populated with dataemit()- Sends the log record to the logging pipelineevent_enabled()- Allows early filtering to skip expensive logging operations
When
emit() is called within an active trace context, the logger automatically attaches the current trace ID, span ID, and trace flags to the log record.LoggerProvider
TheLoggerProvider trait creates Logger instances:
LogRecord
TheLogRecord trait provides methods to populate log record fields:
Core Types
Severity
TheSeverity enum defines 24 log severity levels:
AnyValue
TheAnyValue enum represents values that can be stored in log attributes or body:
Performance consideration: The
log and tracing crates only support basic types (i64, f64, strings, bool). Complex types like ListAny and Map are available for custom appenders but involve heap allocations.SDK Implementation
Theopentelemetry-sdk crate provides the concrete implementation:
SdkLogRecord
The SDK’sSdkLogRecord implements the LogRecord trait and stores:
- Timestamps (event time and observed time)
- Severity (number and text)
- Body (the log message)
- Attributes (structured key-value data)
- Trace context (trace ID, span ID, flags)
- Target (module/component identifier)
- Event name (optional event identifier)
Building a Log Appender
Here’s how to build a custom log appender using the Bridge API:1
Get a Logger
Obtain a logger from the provider:Note: Log appenders typically use an empty scope name. See the semantic conventions issue.
2
Create a LogRecord
When a log event occurs:
3
Populate the LogRecord
Map fields from the logging library to the log record:
4
Emit the LogRecord
Send the log record to the pipeline:
Example: Simple Appender
Performance Optimization
event_enabled Check
Always checkevent_enabled() before expensive operations:
Target Field
Thetarget field serves a special purpose:
- Used for filtering and routing logs
- Exporters may use this as the instrumentation scope name
- Both
logandtracingappenders default to the module path
Noop Implementation
For testing or when logging is disabled, use the noop provider:See Also
log Appender
Implementation using the
log cratetracing Appender
Implementation using the
tracing crateLog Processors
Processing and exporting log records
Overview
Return to logs overview