OTLP
class
Defined in src/logit/backends/otlp.cr:50
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
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.
#flush
Forces an immediate flush of buffered events.
#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.
Nested Types
BatchProcessor-Batches events and flushes them periodically or when size threshold is reached.
Config-Configuration options for the OTLP backend.
HttpClient-HTTP client wrapper for sending OTLP payloads.
PayloadBuilder-Builds OTLP JSON payloads from Logit events.