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) (spanCtx context.Context, endSpan func(err ...error))
- func TraceID(ctx context.Context) string
- 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) RecordStream(ctx context.Context, stats StreamStats)
- func (p *Provider) RegisterCheck(name string, checkFunc func(context.Context) error)
- func (p *Provider) Sink() *Sink
- func (p *Provider) Tracer(name string) trace.Tracer
- type Sink
- type StreamBytes
- type StreamError
- type StreamExecution
- type StreamIdentity
- type StreamItems
- type StreamStats
- type StreamStatus
- type TraceCollector
- 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 must be in [0,1]. A zero value defaults to 1 unless
// SampleRatioSet is true, which distinguishes explicit zero sampling.
SampleRatio float64
SampleRatioSet bool
HealthCheckTimeout time.Duration
PrometheusRegistry *prometheus.Registry
MetricsPrefix string
MetricsNamespace string
MetricsSubsystem string
HistogramBuckets []float64
LoggerHandler slog.Handler
TraceProcessor sdktrace.SpanProcessor
}
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) Hook ¶
Hook initializes an execution Hook from the Provider. The tracer is taken from the provider's own TracerProvider rather than the global one, so hooks stay valid when another Provider is installed on the global slot (parallel tests, multiple providers in one process).
func (*Provider) LLMMetrics ¶ added in v0.2.0
func (*Provider) MetricsHandler ¶
MetricsHandler provides standard HTTP handler for Prometheus scraping.
func (*Provider) RecordStream ¶ added in v0.4.0
func (p *Provider) RecordStream(ctx context.Context, stats StreamStats)
func (*Provider) RegisterCheck ¶
RegisterCheck attaches a readiness health probe.
type Sink ¶ added in v0.2.0
type Sink struct {
// contains filtered or unexported fields
}
func (*Sink) RecordStream ¶ added in v0.4.0
func (s *Sink) RecordStream(ctx context.Context, stats StreamStats)
RecordStream enriches the active OpenTelemetry span with stream execution metrics.
type StreamBytes ¶ added in v0.4.0
type StreamError ¶ added in v0.4.0
type StreamExecution ¶ added in v0.4.0
type StreamIdentity ¶ added in v0.4.0
type StreamItems ¶ added in v0.4.0
type StreamStats ¶ added in v0.4.0
type StreamStats struct {
Stream StreamIdentity `json:"stream"`
Exec StreamExecution `json:"execution"`
Items StreamItems `json:"items"`
Bytes StreamBytes `json:"bytes,omitzero"`
Error *StreamError `json:"error,omitempty"`
}
type StreamStatus ¶ added in v0.4.0
type StreamStatus string
const ( StreamStatusCompleted StreamStatus = "completed" StreamStatusFailed StreamStatus = "failed" StreamStatusCanceled StreamStatus = "canceled" StreamStatusTimeout StreamStatus = "timeout" StreamStatusStopped StreamStatus = "stopped" )
type TraceCollector ¶ added in v0.3.0
type TraceCollector struct {
// contains filtered or unexported fields
}
TraceCollector is a true circular ring buffer with index arithmetic (zero slice reallocations).
func WithCollector ¶
func WithCollector(ctx context.Context) (context.Context, *TraceCollector)
WithCollector attaches a TraceCollector to the context for capturing spans.
func (*TraceCollector) Spans ¶ added in v0.3.0
func (c *TraceCollector) Spans() []CompletedSpan
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. |
|
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. |
|
Package nexssflow adapts Nexss Observability to Nexss Flow.
|
Package nexssflow adapts Nexss Observability to Nexss Flow. |