Documentation
ΒΆ
Overview ΒΆ
Package obs provides OpenTelemetry-based tracing, metrics, contextual logging, and readiness health probes.
Package obs provides tracing hooks for framework action execution.
Package obs provides interfaces for observability components.
Package obs provides OpenTelemetry contextual logging.
Package obs initializes OpenTelemetry meters, tracers, Prometheus registries, and health endpoints.
Index ΒΆ
- func FormatDuration(d time.Duration) string
- func SpanID(ctx context.Context) string
- func StartSpan(ctx context.Context, name string, detail ...string) (context.Context, func(err ...error))
- func TraceID(ctx context.Context) string
- func WithCollector(ctx context.Context) (context.Context, *activeTraceCollector)
- type CompletedSpan
- type Config
- type ContextHandler
- type HealthChecker
- type HealthRegistry
- type Hook
- type Option
- type Provider
- func Auto() (*Provider, func(context.Context) error, error)
- func AutoWithOptions(opts ...Option) (*Provider, func(context.Context) error, error)
- func New(ctx context.Context, cfg Config, opts ...Option) (*Provider, error)
- func NewWithShutdown(cfg Config) (*Provider, func(context.Context) error, error)
- func (p *Provider) Config() Config
- func (p *Provider) Handler() slog.Handler
- func (p *Provider) HealthHandler() http.Handler
- func (p *Provider) Hook() *Hook
- func (p *Provider) Logger() *slog.Logger
- func (p *Provider) MetricsHandler() http.Handler
- func (p *Provider) RegisterCheck(name string, checkFunc func(context.Context) error)
- type TraceRecord
- type Tracer
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func FormatDuration ΒΆ
func StartSpan ΒΆ
func StartSpan(ctx context.Context, name string, detail ...string) (context.Context, func(err ...error))
StartSpan creates a child OpenTelemetry span with start offsets for visual timelines.
Types ΒΆ
type CompletedSpan ΒΆ
type CompletedSpan struct {
Name string `json:"name"`
Status string `json:"status"` // "OK" or "ERROR"
StartOffsetUs int64 `json:"start_offset_us"`
StartOffsetNs int64 `json:"start_offset_ns"`
DurationUs int64 `json:"duration_us"`
DurationNs int64 `json:"duration_ns"`
Duration string `json:"duration"`
Detail string `json:"detail,omitempty"`
}
type Config ΒΆ
type Config struct {
ServiceName string
NodeID string
Env string
OTLPEndpoint string
OTLPHeaders map[string]string
OTLPInsecure bool
SampleRatio float64
HealthCheckTimeout time.Duration
PrometheusRegistry *prometheus.Registry
MetricsPrefix string
MetricsNamespace string
MetricsSubsystem string
HistogramBuckets []float64
LoggerHandler slog.Handler
}
Config holds observability initialization parameters.
func LoadConfigFromEnv ΒΆ
func LoadConfigFromEnv() Config
LoadConfigFromEnv builds Config from standard environment variables.
type ContextHandler ΒΆ
ContextHandler wraps a slog.Handler to inject active trace and span IDs into log records.
func NewContextHandler ΒΆ
func NewContextHandler(base slog.Handler) *ContextHandler
NewContextHandler constructs a ContextHandler around a base slog.Handler.
func (*ContextHandler) Enabled ΒΆ
Enabled reports whether the handler handles records at the given level.
func (*ContextHandler) Handle ΒΆ
Handle injects OpenTelemetry trace context and action metadata into the slog.Record.
type HealthChecker ΒΆ
HealthChecker defines a component that can be polled for readiness.
type HealthRegistry ΒΆ
type HealthRegistry interface {
RegisterCheck(name string, check func(ctx context.Context) error)
HealthHandler() http.Handler
}
HealthRegistry allows dynamic registration of system readiness probes.
type Hook ΒΆ
type Hook struct {
// contains filtered or unexported fields
}
Hook instruments action executions with OpenTelemetry spans and metrics.
type Option ΒΆ
type Option func(*Config)
func WithLoggerHandler ΒΆ
func WithMetricsPrefix ΒΆ
func WithPrometheusRegistry ΒΆ
func WithPrometheusRegistry(reg *prometheus.Registry) Option
type Provider ΒΆ
type Provider struct {
// contains filtered or unexported fields
}
Provider manages OpenTelemetry meters, tracers, and health checks.
func AutoWithOptions ΒΆ
AutoWithOptions initializes observability with optional functional modifications.
func NewWithShutdown ΒΆ
NewWithShutdown instantiates Provider alongside an explicit cleanup function.
func (*Provider) HealthHandler ΒΆ
HealthHandler serves JSON HTTP readiness probe responses.
func (*Provider) MetricsHandler ΒΆ
MetricsHandler provides standard HTTP handler for Prometheus scraping.
type TraceRecord ΒΆ
type TraceRecord struct {
TraceID string `json:"trace_id"`
Action string `json:"action"`
Transport string `json:"transport"`
Timestamp time.Time `json:"timestamp"`
TotalDurationUs int64 `json:"total_duration_us"`
Duration string `json:"duration"`
Status string `json:"status"`
Spans []CompletedSpan `json:"spans"`
}
func TraceRecordFromContext ΒΆ
func TraceRecordFromContext(ctx context.Context, actionName, transportName string, err error) (TraceRecord, bool)
TraceRecordFromContext builds a complete, machine-readable trace record (timeline) from the context. Returns false if there was no active collector in the context (WithCollector).
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
Package actionhook adapts *obs.Hook to the framework action system.
|
Package actionhook adapts *obs.Hook to the framework action system. |
|
Package dbtrace provides OpenTelemetry tracing wrappers for database/sql operations.
|
Package dbtrace provides OpenTelemetry tracing wrappers for database/sql operations. |
|
Package events provides business telemetry event emission.
|
Package events provides business telemetry event emission. |
|
examples
|
|
|
01_zero_touch_ap
command
|
|
|
02_context_propagation
command
|
|
|
03_advanced_observability
command
|
|
|
Package httptrace provides OpenTelemetry instrumentation wrappers for http Clients and Transports.
|
Package httptrace provides OpenTelemetry instrumentation wrappers for http Clients and Transports. |