observability

package
v0.60.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package observability owns the process-global OpenTelemetry providers (tracer and logger). They are initialized once during server startup and shut down once at exit, so telemetry is server-level infrastructure rather than a toggleable plugin.

When no OTLP endpoint or signal-specific exporter is configured (or OTEL_SDK_DISABLED=true), Init is a no-op: the global providers stay the SDK defaults (no-op), and Shutdown does nothing. Exporter transport details (protocol, headers, TLS) are resolved by the OTel exporters from their standard environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(h http.Handler) http.Handler

Handler wraps h with OpenTelemetry HTTP server instrumentation so every inbound request produces a server span. It is always applied: when tracing is disabled the global provider is a no-op, so wrapping adds negligible overhead and keeps the server's handler composition unconditional.

The span name formatter gives each span a "<METHOD> <templated-path>" name. Path segments that look like resource instance IDs are collapsed to a placeholder (see templatePath) so /api/projects/123 and /api/projects/456 share one span name — span names are an aggregation key, and raw instance paths would explode cardinality in the tracing backend.

func NewTraceContextHandler added in v0.60.0

func NewTraceContextHandler(next slog.Handler) slog.Handler

NewTraceContextHandler wraps next so records logged with a span-carrying context (the slog *Context variants) gain trace_id/span_id attributes. The OTLP log bridge extracts trace context natively; this wrapper gives the console output the same correlation, so an operator can jump from a stderr line to the trace in their backend. Records logged without a context pass through unchanged.

Types

type Config

type Config struct {
	Enabled     bool   // true when trace export is configured and the SDK is not disabled
	ServiceName string // OTel service name, defaults to "stella"
}

Config holds OTel settings derived from standard environment variables. Exporter-level vars (endpoint, protocol, headers, TLS) are consumed by the auto exporters and are not duplicated here.

func LoadConfig

func LoadConfig() Config

LoadConfig reads OTel settings from the environment. Tracing is enabled when the span exporter has something to export to — either an OTLP endpoint (the generic or traces-specific variable) or an explicit OTEL_TRACES_EXPORTER such as "console" — and the operator has not opted out. OTEL_SDK_DISABLED=true and OTEL_TRACES_EXPORTER=none are the standard kill switches; either silences trace export even when an endpoint is present.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is the lifecycle handle for global OTel providers. The zero value (and any Provider returned when OTel is disabled) is a valid no-op: Shutdown returns nil without touching anything.

func Init

func Init(ctx context.Context) (*Provider, error)

Init loads OTel config and, when an exporter endpoint is configured, builds the enabled providers, installs them as globals, and returns a Provider whose Shutdown flushes pending telemetry. When disabled it returns a no-op Provider and leaves the global providers as the SDK defaults.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown flushes pending telemetry and stops the providers. It is a no-op when OTel is disabled. The caller controls the deadline via ctx.

Directories

Path Synopsis
Package tracehook is the core agent trace hook: it logs LLM, tool, and memory activity via slog and, when OTel tracing is enabled, records the session/turn/LLM/tool/memory span hierarchy.
Package tracehook is the core agent trace hook: it logs LLM, tool, and memory activity via slog and, when OTel tracing is enabled, records the session/turn/LLM/tool/memory span hierarchy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL