Documentation
¶
Overview ¶
Package logkit is what a log record names: its event, defined once, and the trace it was written in.
A record's msg is a sentence for people; its event is the name programs match on (alert rules, dashboards, searches), a soft contract kept compatible as best anfra can (docs/designs/logs.md). An event is defined at package level with DefineEvent, never invented at a call site, so Events lists every event a binary can write:
var eventFailed = logkit.DefineEvent("routine.failed", "A routine's run returned an error.",
"routine", "outcome", "error")
logger.ErrorContext(ctx, "Routine failed", logkit.EventKey, eventFailed, "routine", name, ...)
TraceHandler adds the trace and span a record was written in, so one request's records join across services.
Index ¶
Constants ¶
const EventKey = "event"
EventKey is the attribute that carries a record's event.
Variables ¶
This section is empty.
Functions ¶
func TraceHandler ¶
TraceHandler wraps h to add the trace and span a record was written in, from the context it was logged with, as trace_id and span_id: OpenTelemetry's names for trace context in JSON logs. They join one request's records across services, and link each to its span. A record logged without a context, or outside any span, has neither.
They go where the record's own attributes go: under a logger's group, if it has one, so a logger that writes records with an event has none.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is something that happened, as programs reading the log know it. As an attribute's value, it is its name.
func DefineEvent ¶
DefineEvent defines an event: its name, what it means, and the attributes its records may carry. Call it from a package-level var, once per name; a name already defined or not <area>.<what happened> in snake_case, no doc, or an attribute not snake_case or listed twice panics at startup.
func Events ¶
func Events() []Event
Events is every event defined in this binary, in definition order.
func (Event) Attrs ¶
Attrs are the attributes its records may carry, besides those every record has.