Documentation
¶
Overview ¶
Package tracelog renders request-grouped logs as traces.
A trace is the set of log lines sharing a request ID. Render prints one block per trace: a header summarizing the request, then each line with its offset from the start of the trace:
2026-07-06 12:29:20 req-06FKH... POST /Identity_Login 500 1ms +0s INFO http request agent=curl/8.7.1 remote=[::1]:52161 +638µs ERROR invalid credentials +638µs ERROR http response error=invalid credentials written=34
Collector renders traces live as requests complete, from any stream of slog JSON lines (ParseLine). The same code serves dev (cmd/dev tails the server it starts) and production (the traces CLI reads server log files), so both environments see identical output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Anomalies ¶
Anomalies inspects a completed trace for shapes that usually indicate silent failures: successful responses whose side effects never happened. It derives everything from the trace's entries, so detectors work on any log stream, past or live, without app-side support.
func FormatDuration ¶
FormatDuration trims a duration to a readable precision for log output, e.g. "12.35ms" rather than "12.345678ms".
func IsTerminal ¶
IsTerminal reports whether w writes to a terminal, for deciding whether to render with color.
func Render ¶
Render writes one trace block: a header line summarizing the request, then each entry with its offset from the first entry. The method, path, status, and duration attributes of the "http request" and "http response" entries are hoisted into the header.
Types ¶
type Collector ¶
type Collector struct {
Out io.Writer
// MaxAge bounds how long an unfinished trace is buffered. Zero means
// 30 seconds.
MaxAge time.Duration
// PassThrough prints entries that have no request ID as single lines.
// When false those entries are dropped.
PassThrough bool
// Filter, when set, decides whether a completed trace is rendered.
Filter func(id string, entries []Entry) bool
// Color renders anomaly callouts in yellow ANSI color. Enable when Out
// is a terminal (IsTerminal).
Color bool
// contains filtered or unexported fields
}
Collector groups a stream of log entries into traces and renders each trace as soon as its request completes (the "http response" entry). Unfinished traces are flushed after MaxAge so hung or crashed requests still show their logs.
func (*Collector) Add ¶
Add feeds one log entry to the collector. Entries with an empty id are printed immediately (or dropped, per PassThrough); others are buffered under their trace until the trace completes.
Source Files
¶
- anomaly.go
- collect.go
- tracelog.go