observability

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package observability provides unified logging, tracing, and metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerFromContext

func LoggerFromContext(ctx context.Context, fallback *slog.Logger) *slog.Logger

LoggerFromContext retrieves the logger from context, falling back to the provided default.

func NewNoopMeter

func NewNoopMeter() metric.Meter

NewNoopMeter returns a no-op meter for testing.

func NewNoopTracer

func NewNoopTracer() trace.Tracer

NewNoopTracer returns a no-op tracer for testing.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

RequestIDFromContext retrieves the request ID from the context.

func WithLogger

func WithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger stores a logger in the context.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID stores a request ID in the context.

Types

type HTTPMiddleware

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

HTTPMiddleware provides observability middleware for HTTP handlers.

func NewHTTPMiddleware

func NewHTTPMiddleware(p *Provider) *HTTPMiddleware

NewHTTPMiddleware creates a new HTTP observability middleware.

func (*HTTPMiddleware) Logging

func (m *HTTPMiddleware) Logging() func(http.Handler) http.Handler

Logging returns middleware that logs every HTTP request with structured fields.

func (*HTTPMiddleware) Metrics

func (m *HTTPMiddleware) Metrics() func(http.Handler) http.Handler

Metrics returns middleware that records HTTP request count and latency.

func (*HTTPMiddleware) Recover

func (m *HTTPMiddleware) Recover() func(http.Handler) http.Handler

Recover returns middleware that recovers from panics, logs the error, and returns 500.

func (*HTTPMiddleware) RequestID

func (m *HTTPMiddleware) RequestID() func(http.Handler) http.Handler

RequestID returns middleware that generates a unique request ID, stores it in context, adds X-Request-ID header, and creates a child logger.

func (*HTTPMiddleware) Tracing

func (m *HTTPMiddleware) Tracing() func(http.Handler) http.Handler

Tracing returns middleware that extracts propagated trace context and creates a server span for each request.

type Metrics

type Metrics struct {
	// Counters
	TokensIssued      metric.Int64Counter
	TokensRefreshed   metric.Int64Counter
	TokensRevoked     metric.Int64Counter
	AuthDenied        metric.Int64Counter
	ClientsRegistered metric.Int64Counter
	ConsentDecisions  metric.Int64Counter
	LoginAttempts     metric.Int64Counter
	RefreshTokenReuse metric.Int64Counter

	// Histograms
	TokenIssuanceDuration metric.Float64Histogram
	AuthFlowDuration      metric.Float64Histogram
	CIMDFetchDuration     metric.Float64Histogram
	DBOperationDuration   metric.Float64Histogram

	// OIDC
	OIDCExchangeDuration metric.Float64Histogram
	OIDCJWKSCacheHits    metric.Int64Counter
	OIDCJWKSCacheMisses  metric.Int64Counter

	// Introspection
	IntrospectionDuration metric.Float64Histogram
	IntrospectionTotal    metric.Int64Counter

	// Signing key management
	KeyRotationTotal  metric.Int64Counter
	KeyReloadDuration metric.Float64Histogram

	// Upstream broker connections (the AS-side of vending upstream-format
	// access tokens to MCP clients via stored per-user credentials).
	UpstreamTokenIssuedTotal      metric.Int64Counter
	UpstreamTokenIssuanceDuration metric.Float64Histogram
	UpstreamTokenRefreshTotal     metric.Int64Counter
	ConnectionConnectTotal        metric.Int64Counter
	ConnectionDisconnectTotal     metric.Int64Counter

	// Client Credentials (Phase 3)
	ClientCredentialsIssued metric.Int64Counter
	ClientCredentialsDenied metric.Int64Counter

	// DPoP (Phase 3 — RFC 9449)
	DPoPProofsValidated metric.Int64Counter
	DPoPProofsRejected  metric.Int64Counter

	// Token Exchange (Phase 3 — RFC 8693)
	TokenExchangeTotal  metric.Int64Counter
	TokenExchangeDenied metric.Int64Counter

	// Agent Identity (Phase 3 — Authplane extension)
	AgentTokensIssued metric.Int64Counter

	// XAA — Enterprise-Managed Authorization
	XAAPolicyEvaluationTotal metric.Int64Counter
	XAAIDPOperationsTotal    metric.Int64Counter
	XAASubjectResolutions    metric.Int64Counter

	// Resource Server + Cross-Client Allowlist admin operations
	ResourceServerOps metric.Int64Counter
	AllowlistOps      metric.Int64Counter

	// Gauges
	ActiveClients       metric.Int64UpDownCounter
	ActiveTokenFamilies metric.Int64UpDownCounter

	// HTTP (registered here, used in middleware)
	HTTPRequestDuration metric.Float64Histogram
	HTTPRequestsTotal   metric.Int64Counter
}

Metrics holds all pre-registered application metric instruments.

type MultiHandler

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

MultiHandler fans out log records to multiple handlers.

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a handler that writes to all provided handlers.

func (*MultiHandler) Enabled

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

Enabled implements slog.Handler.

func (*MultiHandler) Handle

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

Handle implements slog.Handler.

func (*MultiHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*MultiHandler) WithGroup

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

WithGroup implements slog.Handler.

type Provider

type Provider struct {
	Logger  *slog.Logger
	Tracer  trace.Tracer
	Meter   metric.Meter
	Metrics *Metrics
	// contains filtered or unexported fields
}

Provider holds all observability components.

func New

New creates a fully-wired observability provider from configuration. Returns the provider, a shutdown function, and any error.

func NewNoop

func NewNoop() *Provider

NewNoop creates a no-op Provider suitable for testing.

func Setup

Setup creates a provider (backward-compatible wrapper around New).

func (*Provider) PrometheusHandler

func (p *Provider) PrometheusHandler() http.Handler

PrometheusHandler returns the Prometheus metrics HTTP handler, or nil if not using Prometheus.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down tracing/metrics exporters.

func (*Provider) WithComponent

func (p *Provider) WithComponent(component string) *Provider

WithComponent returns a derivative Provider scoped to a component name.

type TraceContextHandler

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

TraceContextHandler injects trace_id, span_id, and request_id into every log record.

func NewTraceContextHandler

func NewTraceContextHandler(inner slog.Handler) *TraceContextHandler

NewTraceContextHandler wraps a handler to inject trace context attributes.

func (*TraceContextHandler) Enabled

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

Enabled implements slog.Handler.

func (*TraceContextHandler) Handle

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

Handle implements slog.Handler.

func (*TraceContextHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*TraceContextHandler) WithGroup

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

WithGroup implements slog.Handler.

Jump to

Keyboard shortcuts

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