observability

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package observability provides Draugr's logging and telemetry foundations: structured logging via log/slog and distributed tracing via OpenTelemetry.

Security note: logs and spans must never carry secrets (tokens, credentials, full request/response bodies). Scanners and plugins are responsible for redacting sensitive values before they reach a logger or span attribute.

Index

Constants

View Source
const LevelTrace = slog.LevelDebug - 4

LevelTrace is below debug: it relays what Draugr's dependencies print, which is verbose and only wanted when debug hasn't answered the question.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(w io.Writer, opts LogOptions) (*slog.Logger, error)

NewLogger builds a slog.Logger writing to w according to opts.

The default format is a human-readable console: Draugr is developer-first, so a person running it in a terminal should see legible, colorized logs, not JSON. Color is emitted only when w is an interactive terminal (and NO_COLOR is unset), so piped or redirected output stays plain text. Structured JSON is available on demand (Format "json") for CI and observability pipelines that consume machine-readable logs.

func SetDefault

func SetDefault(l *slog.Logger)

SetDefault installs l as the process-wide default slog logger.

Types

type LogOptions

type LogOptions struct {
	Level  string // trace | debug | info | warn | error
	Format string // console | json | text
}

LogOptions configures the structured logger.

type ShutdownFunc

type ShutdownFunc func(context.Context) error

ShutdownFunc flushes and releases telemetry resources. It is always safe to call.

func InitMetrics

func InitMetrics(ctx context.Context, service, version string) (ShutdownFunc, error)

InitMetrics configures an OpenTelemetry meter provider for the process.

Like tracing, it is opt-in and standards-based: with no OTLP endpoint configured via the standard OTEL_EXPORTER_OTLP_ENDPOINT / OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variables, metrics are a no-op. When an endpoint is set, metrics are exported over OTLP/gRPC. Returns a shutdown func that flushes and releases resources.

func InitTracing

func InitTracing(ctx context.Context, service, version string) (ShutdownFunc, error)

InitTracing configures an OpenTelemetry tracer provider for the process.

It is opt-in and standards-based: if no OTLP endpoint is configured via the standard OTEL_EXPORTER_OTLP_ENDPOINT / OTEL_EXPORTER_OTLP_TRACES_ENDPOINT environment variables, tracing is a no-op with zero overhead. When an endpoint is set, spans are exported over OTLP/gRPC. All exporter tuning (endpoint, headers, TLS, sampling) uses the standard OTEL_* environment variables.

Jump to

Keyboard shortcuts

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