Documentation
¶
Index ¶
Constants ¶
const LevelCritical slog.Level = slog.LevelError + 4
LevelCritical is emitted for unrecoverable conditions (panics, data corruption, failed invariants). Sits above slog.LevelError so it surfaces above normal error noise in log aggregators. Value mirrors the OTel SeverityFatal range so the otelslog bridge maps it correctly.
Variables ¶
var StderrSink io.Writer = os.Stderr
StderrSink is the destination for log output configured as "stderr" (log.app.output / log.http.output) when no explicit writer is supplied. Defaults to os.Stderr. The server test suite repoints it at GinkgoWriter (via testutil) so the HTTP access logger — constructed deep inside BuildApp with no injection seam — doesn't interleave JSON lines with spec output.
Functions ¶
func NewContextEnrichingHandler ¶
NewContextEnrichingHandler wraps h so that every record emitted through it gets request-scoped attributes pulled from ctx: request_id, user_id, user_email, http.route. Attrs are added only when ctx carries the source; records from non-HTTP code paths remain unchanged.
Types ¶
type Config ¶
type Config struct {
ServiceName string
ServiceVersion string
ServiceCommit string
ServiceBuildDate string
// StderrWriter receives human-readable log output. Defaults to os.Stderr.
// Tests can override with GinkgoWriter.
StderrWriter io.Writer
}
Config carries service identity + stderr log sink. OTLP endpoint + log level/format are read from the config singleton at Setup time — they're operator-tunable. Service identity comes from -ldflags (version, commit, build date) so it's always a direct arg.
type HTTPLogger ¶
type HTTPLogger struct {
// contains filtered or unexported fields
}
HTTPLogger emits one access-log line per non-skipped HTTP request to a dedicated sink (stderr or a rotating file) and, when an OTel logger provider is registered, to the OTel logs pipeline. Returned nil when http access logging is disabled by config.
func NewHTTPLogger ¶
func NewHTTPLogger(cfg config.HTTPLog) (*HTTPLogger, error)
NewHTTPLogger constructs an HTTPLogger from cfg. Returns nil, nil when cfg.Enabled is false. Errors when output path is relative or format is not one of "json" or "combined".
func (*HTTPLogger) Close ¶
func (l *HTTPLogger) Close() error
Close flushes and closes the underlying writer. No-op for stderr.
func (*HTTPLogger) Middleware ¶
Middleware emits one access-log line per non-skipped request, captured on the way out of the handler chain so status/bytes/duration reflect the final response. When the HTTPLogger is nil (disabled), returns a passthrough so callers don't have to branch.
type Shutdown ¶
Shutdown flushes and shuts down all OTel providers (tracer, meter, logger).
func Setup ¶
Setup initializes the full observability pipeline and returns the slog handler the caller must install via slog.SetDefault. The handler fans log records out to:
- a stderr text/json handler (always), for local visibility and crashes.
- the OTel logs bridge (when Endpoint is set), for centralized collection.
Traces and metrics providers are also registered as OTel globals when the endpoint is set. All three signals share one resource.