class
Logit::Backend::OTLP
- Logit::Backend::OTLP
- Logit::Backend
- Reference
- Object
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
- 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.
Defined in:
logit/backends/otlp.crlogit/backends/otlp/batch_processor.cr
logit/backends/otlp/config.cr
logit/backends/otlp/http_client.cr
logit/backends/otlp/payload_builder.cr
Constructors
-
.new(config : Config, name = "otlp", level = LogLevel::Info)
Creates a new OTLP backend with the given configuration.
Instance Method Summary
-
#close : Nil
Stops the batch processor and closes the HTTP client.
-
#flush : Nil
Forces an immediate flush of buffered events.
-
#log(event : Event) : Nil
Logs an event by adding it to the batch buffer.
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
Creates a new OTLP backend with the given configuration.
Instance Method Detail
Stops the batch processor and closes the HTTP client.
Flushes any remaining buffered events before closing.
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.