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 ΒΆ
- Constants
- 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) LLMMetrics() *llm.Metrics
- func (p *Provider) Logger() *slog.Logger
- func (p *Provider) MetricsHandler() http.Handler
- func (p *Provider) RegisterCheck(name string, checkFunc func(context.Context) error)
- func (p *Provider) Sink() *Sink
- type Sink
- type TraceRecord
- type Tracer
Constants ΒΆ
const DefaultCollectorCapacity = 64
Variables ΒΆ
This section is empty.
Functions ΒΆ
func FormatDuration ΒΆ
Types ΒΆ
type CompletedSpan ΒΆ
type CompletedSpan struct {
Name string `json:"name"`
Status string `json:"status"` // "OK", "ERROR", or "SUSPENDED"
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.
func (*Hook) After ΒΆ
After ends the OpenTelemetry span and records latency/error/suspension metrics.
type Option ΒΆ
type Option func(*Config)
func WithHistogramBuckets ΒΆ added in v0.2.0
func WithLoggerHandler ΒΆ
func WithMetricsNamespace ΒΆ added in v0.2.0
func WithMetricsPrefix ΒΆ
func WithMetricsSubsystem ΒΆ added in v0.2.0
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) LLMMetrics ΒΆ added in v0.2.0
func (*Provider) MetricsHandler ΒΆ
MetricsHandler provides standard HTTP handler for Prometheus scraping.
func (*Provider) RegisterCheck ΒΆ
RegisterCheck attaches a readiness health probe.
type Sink ΒΆ added in v0.2.0
type Sink struct {
// contains filtered or unexported fields
}
Sink bridges kernel/observe.Event lifecycle events to OpenTelemetry and Prometheus.
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 ΒΆ
Source Files
ΒΆ
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
|
|
|
04_llm_telemetry_example
command
|
|
|
Package httptrace provides OpenTelemetry instrumentation wrappers for http Clients and Transports.
|
Package httptrace provides OpenTelemetry instrumentation wrappers for http Clients and Transports. |
|
Package llm provides OpenTelemetry and Prometheus instrumentation for LLM calls.
|
Package llm provides OpenTelemetry and Prometheus instrumentation for LLM calls. |