observability

package
v0.68.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: AGPL-3.0 Imports: 33 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 ConsoleOnlyLogger

func ConsoleOnlyLogger() *slog.Logger

ConsoleOnlyLogger returns a logger that bypasses the OTLP leg. It is for diagnostic details that may contain raw upstream error text; all routine records must continue through slog.Default().

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

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.

func RecordSpanError

func RecordSpanError(span trace.Span, err error, status string)

RecordSpanError records only a closed error class on a span. Error messages can contain upstream bodies, commands, URLs, or prompt fragments, so they stay in logs and never become exported span status text or exception events.

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. Whether a signal is exporting is decided by package otelenv, which is also what the HTTP transport asks before it emits provider spans — one answer, one place.

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) ForceFlushLogs

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

ForceFlushLogs makes log-export tests and controlled shutdown paths wait for the current batch without exposing the provider implementation.

func (*Provider) MetricsEnabled

func (p *Provider) MetricsEnabled() bool

MetricsEnabled reports whether Init installed a real meter provider.

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 metrichook records bounded agent-loop metrics from the core hook payloads.
Package metrichook records bounded agent-loop metrics from the core hook payloads.

Jump to

Keyboard shortcuts

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