Documentation
¶
Overview ¶
Package tracelog is the platform's log handler (#1894): JSON records to stderr, each stamped with the trace_id and span_id of the span its context carries, so a stderr line and the span of the call that wrote it are joined by one id; and, when the deployment exports log records over OTLP, the same records fanned out to the export handler at the same level.
Build assembles it. Handler is the stamp alone, for a sink of the caller's choosing. The package reads the span off the context and knows nothing about the platform, which is what makes it usable before the platform exists: the composition root installs it as the default logger's handler first, and every slog.*Context call after that is correlated.
Index ¶
Constants ¶
const ( KeyTraceID = "trace_id" KeySpanID = "span_id" )
The attribute keys, the names the OpenTelemetry log data model and the collector's trace-to-log correlation read.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build assembles the default logger's handler: a JSON handler on w at level, under the trace-id stamp, and, when export is not nil, the export handler beside it under the same level. The OTLP bridge sets the trace ids on its own records from the context, so it is not under the stamp; it is under the level filter so the export follows LOG_LEVEL as stderr does.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an slog.Handler that stamps trace_id and span_id onto a record logged with a context carrying a valid span, then hands it to the handler it wraps. A record logged without a span passes through unchanged.