Sign in

    #OpenTelemetry Logs SDK

    This package implements the SDK objects needed to produce and export log records.

    #Main types

    • SdkLoggerProvider: owns shared resource and processor configuration
    • SdkLogger: creates scoped log records
    • LogRecord: immutable exported log payload
    • BatchConfig: queue and timing configuration for batch export
    • LogProcessor: processing hook interface
    • SimpleLogProcessor, BatchLogProcessor: processor implementations
    • LogExporter: exporter callback wrapper
    • InMemoryLogExporter: test helper

    #Processing model

    Async SdkLogger::emit() snapshots the current provider resource and instrumentation scope into a LogRecord, then forwards that record through every configured processor.

    BatchLogProcessor buffers records in memory. When the queue reaches the batch size it flushes immediately; otherwise it relies on run() to flush on the configured interval. The queue is bounded, and the oldest record is dropped when the queue is full.

    BatchConfig::default() reads:

    • OTEL_BLRP_SCHEDULE_DELAY
    • OTEL_BLRP_MAX_QUEUE_SIZE
    • OTEL_BLRP_MAX_EXPORT_BATCH_SIZE
    • OTEL_BLRP_EXPORT_TIMEOUT

    #Trace-aware logging

    If emit() receives a context with a valid active span, the emitted log record stores a local SpanContext so exporters can correlate logs with traces.

    AnyValue

    pub(all) enum AnyValue {
    Bool(Bool)
    Int64(Int64)
    Double(Double)
    String(String)
    Bytes(Bytes)
    Array(Array[AnyValue])
    Map(Array[KeyValue])
    } derive(Eq, ToJson,
    Debug
    )

    Structured log value preserved by the SDK and OTLP exporter.

    Use Map and Array when the backend should receive structured payloads rather than preformatted strings. Spec: https://opentelemetry.io/docs/specs/otel/common/#anyvalue

    AnyValue::from_common

    Converts a shared SDK attribute value into a log-specific structured value. Spec: https://opentelemetry.io/docs/specs/otel/common/#anyvalue

    BatchConfig

    pub struct BatchConfig {
    max_queue_size : Int
    max_export_batch_size : Int
    scheduled_delay_millis : Int
    export_timeout_millis : Int
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Configuration for batch log processing. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchConfig::new

    fn BatchConfig::new(max_queue_size? : Int, max_export_batch_size? : Int, scheduled_delay_millis? : Int, export_timeout_millis? : Int) -> BatchConfig

    Creates normalized batch log processor configuration. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchLogProcessor

    pub struct BatchLogProcessor {
    inner : LogProcessor
    state :
    Ref
    [BatchProcessorState]
    }

    Processor that buffers log records and exports them in batches.

    The background loop is not started automatically. Use global/facade spawn_background_tasks() after provider registration. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchLogProcessor::into_log_processor

    fn BatchLogProcessor::into_log_processor(self : BatchLogProcessor) -> LogProcessor

    Erases the concrete batch processor type into LogProcessor. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchLogProcessor::new

    Creates a batch log processor with a bounded queue. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchLogProcessor::run

    async fn BatchLogProcessor::run(self : BatchLogProcessor) -> Unit

    Background loop for scheduled batch exports. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

    BatchProcessorState

    type BatchProcessorState

    InMemoryLogExporter

    pub struct InMemoryLogExporter {
    state :
    Ref
    [InMemoryLogExporterState]
    }

    Test exporter that keeps finished logs in memory. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    InMemoryLogExporter::finished_logs

    Returns the finished log records accumulated so far. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    InMemoryLogExporter::into_log_exporter

    fn InMemoryLogExporter::into_log_exporter(self : InMemoryLogExporter) -> LogExporter

    Erases the concrete in-memory exporter type into LogExporter. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#export

    InMemoryLogExporter::new

    Creates an empty in-memory log exporter. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    InMemoryLogExporter::reset

    fn InMemoryLogExporter::reset(self : InMemoryLogExporter) -> Unit

    Clears the in-memory log buffer. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    InMemoryLogExporterState

    type InMemoryLogExporterState

    KeyValue

    Structured log attribute key/value pair. Spec: https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-attributes

    KeyValue::from_common

    Converts a shared SDK attribute into a log-specific structured attribute. Spec: https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-attributes

    KeyValue::new

    fn KeyValue::new(key : StringView, value : AnyValue) -> KeyValue

    Creates a structured log attribute. Spec: https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-attributes

    LogExporter

    pub struct LogExporter {
    export_fn : async (ArrayView[LogRecord]) -> Result[Unit,
    OTelSdkError
    ]
    force_flush_fn : async () -> Result[Unit,
    OTelSdkError
    ]
    shutdown_fn : async () -> Result[Unit,
    OTelSdkError
    ]
    name_fn : () -> String
    }

    Exporter callback wrapper for log batches. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    LogExporter::export_batch

    Exports one batch of log records. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#export

    LogExporter::force_flush

    Requests exporter flush. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#forceflush

    LogExporter::name

    fn LogExporter::name(self : LogExporter) -> String

    Returns a human-readable exporter name. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    LogExporter::new

    fn LogExporter::new(export_fn : async (ArrayView[LogRecord]) -> Result[Unit,
    OTelSdkError
    ], force_flush_fn? : async () -> Result[Unit,
    OTelSdkError
    ], shutdown_fn? : async () -> Result[Unit,
    OTelSdkError
    ], name_fn? : () -> String) -> LogExporter

    Builds a log exporter from callbacks. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

    LogExporter::shutdown

    Requests exporter shutdown. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#shutdown

    LogExporter::shutdown_with_timeout

    async fn LogExporter::shutdown_with_timeout(self : LogExporter, timeout_millis : Int) -> Result[Unit,
    OTelSdkError
    ]

    Requests exporter shutdown with an optional timeout budget in milliseconds. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#shutdown

    LogProcessor

    pub struct LogProcessor {
    emit_fn : async (LogRecord) -> Unit
    force_flush_fn : async () -> Result[Unit,
    OTelSdkError
    ]
    shutdown_fn : async () -> Result[Unit,
    OTelSdkError
    ]
    }

    Processing hook interface for logs.

    Processors receive immutable log snapshots after the logger attaches resource and instrumentation scope metadata. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogProcessor::emit

    async fn LogProcessor::emit(self : LogProcessor, record : LogRecord) -> Unit

    Processes one log record. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogProcessor::force_flush

    Requests processor flush. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogProcessor::new

    fn LogProcessor::new(emit_fn? : async (LogRecord) -> Unit, force_flush_fn? : async () -> Result[Unit,
    OTelSdkError
    ], shutdown_fn? : async () -> Result[Unit,
    OTelSdkError
    ]) -> LogProcessor

    Builds a log processor from callbacks. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogProcessor::shutdown

    Requests processor shutdown. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogProcessor::shutdown_with_timeout

    async fn LogProcessor::shutdown_with_timeout(self : LogProcessor, timeout_millis : Int) -> Result[Unit,
    OTelSdkError
    ]

    Requests processor shutdown with an optional timeout budget in milliseconds. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

    LogRecord

    pub struct LogRecord {
    event_name : String?
    target : String?
    body : AnyValue
    timestamp_unix_nano : Int64
    observed_timestamp_unix_nano : Int64
    severity_number : SeverityNumber?
    severity_text : String?
    attributes : Array[KeyValue]
    trace_context :
    SpanContext
    ?
    resource :
    Resource

    instrumentation_scope :
    InstrumentationScope

    } derive(Eq, ToJson,
    Debug
    )

    Immutable log payload exported by processors and exporters. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#additional-logrecord-interfaces

    LogRecord::new

    fn LogRecord::new(body : AnyValue, timestamp_unix_nano? : Int64, observed_timestamp_unix_nano? : Int64, severity_number? : SeverityNumber?, severity_text? : String?, event_name? : String?, target? : String?, attributes? : ArrayView[KeyValue], trace_context? :
    SpanContext
    ?, resource? :
    Resource
    , instrumentation_scope? :
    InstrumentationScope
    ) -> LogRecord

    Creates a log record snapshot.

    This is the immutable SDK-side representation. Public API users usually build interface/logs.LogRecord values and let Logger::emit() convert them into this type. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#additional-logrecord-interfaces

    LoggerProviderState

    type LoggerProviderState

    SdkLogger

    Logger scoped to one instrumentation library.

    The instrumentation scope is copied onto every emitted log record. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logger

    SdkLogger::emit

    async fn SdkLogger::emit(self : SdkLogger, body : AnyValue, context? :
    Context
    , severity_number? : SeverityNumber?, severity_text? : String?, event_name? : String?, target? : String?, attributes? : ArrayView[KeyValue], timestamp_unix_nano? : Int64, observed_timestamp_unix_nano? : Int64) -> Unit

    Emits one log record through the provider pipeline.

    The logger attaches resource and instrumentation scope metadata before forwarding the record to processors. Spec: https://opentelemetry.io/docs/specs/otel/logs/api/#emit-a-logrecord

    SdkLoggerProvider

    pub struct SdkLoggerProvider {
    state :
    Ref
    [LoggerProviderState]
    }

    Owns resource metadata and the processor pipeline for loggers.

    Applications create one provider, configure processors/exporters, register it if needed, then shut it down during application teardown. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProvider::builder

    Starts building a logger provider with the default resource.

    Add processors or exporters before calling build(). A provider with no processors accepts logs but exports nothing. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProvider::force_flush

    Flushes every configured processor. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#forceflush

    SdkLoggerProvider::into_logger_provider

    Erases this SDK provider into the public logs API provider. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProvider::logger

    fn SdkLoggerProvider::logger(self : SdkLoggerProvider, name : StringView, version? : String?, schema_url? : String?, attributes? : ArrayView[
    KeyValue
    ]) -> SdkLogger

    Creates a logger scoped to the supplied instrumentation library metadata. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#logger-creation

    SdkLoggerProvider::resource

    Returns the provider resource. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProvider::shutdown

    Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#shutdown

    SdkLoggerProvider::shutdown_with_timeout

    async fn SdkLoggerProvider::shutdown_with_timeout(self : SdkLoggerProvider, timeout_millis : Int) -> Result[Unit,
    OTelSdkError
    ]

    Shuts down every configured processor and marks the provider unusable. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#shutdown

    SdkLoggerProvider::spawn_batch_processor_tasks

    fn SdkLoggerProvider::spawn_batch_processor_tasks(self : SdkLoggerProvider, group :
    TaskGroup
    [Unit], allow_failure? : Bool) -> Unit

    Spawns background tasks for all configured batch processors. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder

    pub struct SdkLoggerProviderBuilder {
    resource :
    Resource

    processors : Array[LogProcessor]
    batch_processors : Array[BatchLogProcessor]
    }

    Builder for SdkLoggerProvider. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder::build

    Builds the logger provider. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder::with_batch_exporter

    Appends a batch processor around the exporter and registers it for background execution.

    The processor is registered with the provider, but its export loop only runs after spawn_batch_processor_tasks() or the facade/global equivalent is called. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder::with_log_processor

    Appends a processor to the logger pipeline. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder::with_resource

    Replaces the provider resource. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SdkLoggerProviderBuilder::with_simple_exporter

    Appends a simple processor around the exporter.

    Each emitted log is exported from SdkLogger::emit(). Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#loggerprovider

    SeverityNumber

    pub(all) enum SeverityNumber {
    Trace
    Trace2
    Trace3
    Trace4
    Debug
    Debug2
    Debug3
    Debug4
    Info
    Info2
    Info3
    Info4
    Warn
    Warn2
    Warn3
    Warn4
    Error
    Error2
    Error3
    Error4
    Fatal
    Fatal2
    Fatal3
    Fatal4
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Full OpenTelemetry severity ladder used by LogRecord.

    The 24 slots let bridges preserve finer-grained severity from existing logging frameworks. Spec: https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitynumber

    SimpleLogProcessor

    pub struct SimpleLogProcessor {
    inner : LogProcessor
    }

    Processor that exports each log record immediately.

    Useful for tests and local debugging. Network exporters should usually be wrapped by BatchLogProcessor. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#simple-processor

    SimpleLogProcessor::into_log_processor

    fn SimpleLogProcessor::into_log_processor(self : SimpleLogProcessor) -> LogProcessor

    Erases the concrete simple processor type into LogProcessor. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#simple-processor

    SimpleLogProcessor::new

    Creates a simple processor that exports each emitted record immediately. Spec: https://opentelemetry.io/docs/specs/otel/logs/sdk/#simple-processor

    Source Files