Logit::Event
A structured log event with OpenTelemetry-compatible fields.
Events are the core data structure passed to backends for logging. Each event contains:
- Trace context (trace_id, span_id, parent_span_id)
- Timing information (timestamp, duration)
- Source location (file, line, method, class)
- Structured attributes
- Exception information (if applicable)
Events are created automatically by the instrumentation system. You
typically interact with events through the Span API or by implementing
custom formatters/backends.
OpenTelemetry Semantic Conventions
Events provide helper methods for setting OpenTelemetry semantic attributes:
if span = Logit::Span.current?
# HTTP attributes
span.attributes.set("http.method", "POST")
span.attributes.set("http.route", "/api/users")
span.attributes.set("http.status_code", 200_i64)
# Database attributes
span.attributes.set("db.system", "postgresql")
span.attributes.set("db.statement", "SELECT * FROM users")
end
JSON Serialization
Events serialize to JSON in an OpenTelemetry-compatible format:
{
"trace_id": "abc123...",
"span_id": "def456...",
"timestamp": "2024-01-15T10:30:00.000000Z",
"duration_ms": 42,
"name": "find_user",
"level": "info",
"code": {
"file": "user_service.cr",
"line": 15,
"function": "find_user",
"namespace": "UserService"
},
"attributes": { ... }
}
Constructors
Instance methods
Fully-qualified class name containing the instrumented method.
Span ID of the parent span, or nil if this is a root span.
Span events that occurred during the operation.
These are intermediate logs attached to the span, similar to OpenTelemetry's Span Events.
Span events that occurred during the operation.
These are intermediate logs attached to the span, similar to OpenTelemetry's Span Events.