class Logit::Backend::OTLP

Overview

Backend that exports logs to an OpenTelemetry collector via OTLP/HTTP.

Events are batched and sent as OTLP JSON payloads. The backend flushes either when the batch size is reached or the flush interval elapses.

Basic Usage

Logit.configure do |config|
  config.otlp("http://localhost:4318/v1/logs")
end

With Authentication

Logit.configure do |config|
  config.otlp(
    "https://otlp.example.com/v1/logs",
    headers: {"Authorization" => "Bearer #{ENV["OTLP_TOKEN"]}"},
    resource_attributes: {
      "service.name" => "my-app",
      "service.version" => "1.0.0",
      "deployment.environment" => "production"
    }
  )
end

Configuration Options

Error Handling

The backend never crashes the application. Network errors and failed batches are logged to STDERR and dropped.

Defined in:

logit/backends/otlp.cr
logit/backends/otlp/batch_processor.cr
logit/backends/otlp/config.cr
logit/backends/otlp/http_client.cr
logit/backends/otlp/payload_builder.cr

Constructors

Instance Method Summary

Instance methods inherited from class Logit::Backend

bind(pattern : String, level : LogLevel) : Nil bind, bindings : Array(NamespaceBinding) bindings, bindings=(bindings : Array(NamespaceBinding)) bindings=, close : Nil close, flush : Nil flush, formatter : Formatter | Nil formatter, formatter=(formatter : Formatter | Nil) formatter=, level : LogLevel level, level=(level : LogLevel) level=, log(event : Event) : Nil log, name : String name, name=(name : String) name=, should_log?(event : Event) : Bool should_log?, should_log_level?(level : LogLevel, namespace : String) : Bool should_log_level?

Constructor methods inherited from class Logit::Backend

new(name : String, level : Logit::LogLevel = LogLevel::Info, formatter : Logit::Formatter | Nil = nil) new

Constructor Detail

def self.new(config : Config, name = "otlp", level = LogLevel::Info) #

Creates a new OTLP backend with the given configuration.


[View source]

Instance Method Detail

def close : Nil #

Stops the batch processor and closes the HTTP client.

Flushes any remaining buffered events before closing.


[View source]
def flush : Nil #

Forces an immediate flush of buffered events.


[View source]
def log(event : Event) : Nil #

Logs an event by adding it to the batch buffer.

The event will be sent when the batch size is reached or the flush interval elapses.


[View source]