Documentation
¶
Overview ¶
Package observability provides request tracing, metrics recording, and structured logging helpers for gofly services.
Package observability provides request tracing, metrics recording, structured logging and profiling endpoints for gofly services.
Index ¶
- func Record(registry *metrics.Registry, name string, status int, duration time.Duration)
- func ShouldLog(ctx context.Context, sampler trace.Sampler, status int) bool
- func StartTrace(ctx context.Context, parent string, service string, sampler trace.Sampler) (context.Context, trace.SpanContext)
- func TraceAttrs(ctx context.Context) []any
- type Config
- type LogSamplingConfig
- type LoggerConfig
- type Observe
- type Observer
- type ObserverConfig
- type Operation
- type RotateConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartTrace ¶
func TraceAttrs ¶
Types ¶
type Config ¶
type Config struct {
Service string
Registry *metrics.Registry
Logger *slog.Logger
LogSampler trace.Sampler
}
Config configures the Observer.
type LogSamplingConfig ¶
LogSamplingConfig drops repeated similar messages at high throughput to keep the log volume bounded. A message is identified by level+message. The first First messages of each key pass through; thereafter one message every Thereafter-th is kept, the rest are dropped.
type LoggerConfig ¶
type LoggerConfig struct {
Level slog.Level
JSON bool
AddSource bool
// SetGlobal installs this logger as slog.Default() when non-nil LoggerConfig
// is passed to NewObserve. Disabled by default to avoid surprising side
// effects; enable explicitly when you want free-form slog calls to share the
// same destination and format.
SetGlobal bool
Sampling *LogSamplingConfig
Output io.Writer
// Rotate optionally enables size-based log file rotation. When set,
// Output is ignored and writes go through the rotating file.
Rotate *RotateConfig
}
LoggerConfig controls how the service emits structured logs. If zero, the default is a human-readable text logger at Info level writing to stderr.
type Observe ¶
type Observe struct {
// contains filtered or unexported fields
}
Observe wires together metrics, logging, tracing, and (optionally) pprof diagnostics behind a single http.Handler. Mount it on an internal admin port or under /debug on your main server. This is the "single object" companion to the more granular Observer/Operation API defined in observability.go; pick whichever fits your wiring style.
func NewObserve ¶
func NewObserve(cfg ObserverConfig) *Observe
NewObserve builds and returns an Observe, installing its logger as slog.Default so free-form slog calls share the same formatting.
func (*Observe) Handler ¶
Handler exposes diagnostics endpoints (metrics, json, pprof when enabled) as a single http.Handler. Safe to use with http.ServeMux by prefix.
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer records traces, metrics, and logs for operations.
type ObserverConfig ¶
type ObserverConfig struct {
Service string
Registry *metrics.Registry
Logger *LoggerConfig
Sampler trace.Sampler
Pprof bool
ExposeJSON bool
}
ObserverConfig bundles all observability knobs for a service. The zero value produces sensible defaults: Default metrics registry, text slog, no sampling, pprof exposed under the /debug/pprof/ prefix.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package metrics provides a Prometheus-compatible metrics registry with counters, gauges, histograms and runtime snapshots for gofly services.
|
Package metrics provides a Prometheus-compatible metrics registry with counters, gauges, histograms and runtime snapshots for gofly services. |
|
otel
Package otel bridges the core/metrics Registry to OpenTelemetry, exporting gateway/service metrics over OTLP (gRPC or HTTP) without forcing the core metrics package to depend on the OTel SDK directly.
|
Package otel bridges the core/metrics Registry to OpenTelemetry, exporting gateway/service metrics over OTLP (gRPC or HTTP) without forcing the core metrics package to depend on the OTel SDK directly. |
|
Package trace provides W3C traceparent propagation and OpenTelemetry tracer lifecycle management for gofly services.
|
Package trace provides W3C traceparent propagation and OpenTelemetry tracer lifecycle management for gofly services. |
|
exporter
Package exporter provides convenience constructors for OpenTelemetry trace exporters (OTLP over gRPC or HTTP) so callers can wire core/trace.StartAgent without importing the OTLP SDK packages directly.
|
Package exporter provides convenience constructors for OpenTelemetry trace exporters (OTLP over gRPC or HTTP) so callers can wire core/trace.StartAgent without importing the OTLP SDK packages directly. |