Documentation
¶
Overview ¶
Package observability provides unified logging, tracing, and metrics.
Index ¶
- func LoggerFromContext(ctx context.Context, fallback *slog.Logger) *slog.Logger
- func NewNoopMeter() metric.Meter
- func NewNoopTracer() trace.Tracer
- func RequestIDFromContext(ctx context.Context) (string, bool)
- func WithLogger(ctx context.Context, logger *slog.Logger) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- type HTTPMiddleware
- func (m *HTTPMiddleware) Logging() func(http.Handler) http.Handler
- func (m *HTTPMiddleware) Metrics() func(http.Handler) http.Handler
- func (m *HTTPMiddleware) Recover() func(http.Handler) http.Handler
- func (m *HTTPMiddleware) RequestID() func(http.Handler) http.Handler
- func (m *HTTPMiddleware) Tracing() func(http.Handler) http.Handler
- type Metrics
- type MultiHandler
- type Provider
- type TraceContextHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoggerFromContext ¶
LoggerFromContext retrieves the logger from context, falling back to the provided default.
func NewNoopMeter ¶
NewNoopMeter returns a no-op meter for testing.
func NewNoopTracer ¶
NewNoopTracer returns a no-op tracer for testing.
func RequestIDFromContext ¶
RequestIDFromContext retrieves the request ID from the context.
func WithLogger ¶
WithLogger stores a logger 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.
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.
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 ¶
func New(ctx context.Context, cfg config.ObservabilityConfig) (*Provider, func(context.Context) error, error)
New creates a fully-wired observability provider from configuration. Returns the provider, a shutdown function, and any error.
func Setup ¶
func Setup(cfg config.ObservabilityConfig) *Provider
Setup creates a provider (backward-compatible wrapper around New).
func (*Provider) PrometheusHandler ¶
PrometheusHandler returns the Prometheus metrics HTTP handler, or nil if not using Prometheus.
func (*Provider) WithComponent ¶
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.