Logit::Backend::OTLP
Inherits Logit::Backend / Reference / Object
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
- endpoint: OTLP HTTP endpoint URL (required)
- batch_size: Max events per batch (default: 512)
- flush_interval: Time between flushes (default: 5 seconds)
- headers: HTTP headers for auth (default: empty)
- timeout: HTTP timeout (default: 30 seconds)
- resource_attributes: Service metadata (default: empty)
Error Handling
The backend never crashes the application. Network errors and failed batches are logged to STDERR and dropped.
Constructors
new(config : Config, name = "otlp", level = LogLevel::Info)
Creates a new OTLP backend with the given configuration.
Instance methods
close
Stops the batch processor and closes the HTTP client.
Flushes any remaining buffered events before closing.
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.