observability

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package observability wires structured logging, tracing, and metrics: an slog logger with trace correlation and secret redaction, and OpenTelemetry tracer and meter providers exported via OTLP and Prometheus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(level slog.Level, format string) *slog.Logger

NewLogger builds the application logger: leveled output, trace correlation, and sensitive-value redaction applied to every record. format is "json" (default) or "text".

func ParseLevel

func ParseLevel(s string) slog.Level

ParseLevel maps a config string to an slog.Level, defaulting to info.

Types

type RedactingHandler

type RedactingHandler struct {
	// contains filtered or unexported fields
}

RedactingHandler wraps a slog.Handler and replaces the values of attributes whose key looks sensitive, recursing into groups. It guards against logging credentials by accident, which is the most common log-hygiene failure.

func NewRedactingHandler

func NewRedactingHandler(next slog.Handler) *RedactingHandler

func (*RedactingHandler) Enabled

func (h *RedactingHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*RedactingHandler) Handle

func (h *RedactingHandler) Handle(ctx context.Context, r slog.Record) error

func (*RedactingHandler) WithAttrs

func (h *RedactingHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*RedactingHandler) WithGroup

func (h *RedactingHandler) WithGroup(name string) slog.Handler

type Telemetry

type Telemetry struct {
	Registry *prometheus.Registry
	// contains filtered or unexported fields
}

Telemetry owns the metric registry and a single shutdown hook that flushes and stops every provider in reverse order of construction.

func Setup

func Setup(ctx context.Context, cfg TelemetryConfig) (*Telemetry, error)

Setup wires the global tracer and meter providers and the W3C propagator, returning a Telemetry whose Registry should back the /metrics endpoint.

func (*Telemetry) Shutdown

func (t *Telemetry) Shutdown(ctx context.Context) error

type TelemetryConfig

type TelemetryConfig struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	OTLPEndpoint   string
	SampleRatio    float64
}

TelemetryConfig configures tracing and metrics. When OTLPEndpoint is empty tracing is disabled but metrics (scraped from the returned registry) stay on.

type TraceHandler

type TraceHandler struct {
	// contains filtered or unexported fields
}

TraceHandler injects the active span's trace and span IDs into every record, so a log line links straight to its trace in Tempo. The IDs are read at emit time from the context, so they always reflect the current span.

func NewTraceHandler

func NewTraceHandler(next slog.Handler) *TraceHandler

func (*TraceHandler) Enabled

func (h *TraceHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*TraceHandler) Handle

func (h *TraceHandler) Handle(ctx context.Context, r slog.Record) error

func (*TraceHandler) WithAttrs

func (h *TraceHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*TraceHandler) WithGroup

func (h *TraceHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL