Documentation
¶
Overview ¶
Package observability provides the diagnostic log and OpenTelemetry export. Both are fed from the goroutines doing the work and written by dedicated background goroutines, so logging and tracing never wait on disk or network I/O.
Index ¶
- Constants
- func End(span trace.Span, err error)
- func OpenLog(cfg config.LogConfig, r *redact.Redactor, extra ...slog.Handler) (*slog.Logger, io.Closer, error)
- func ParseLevel(s string) (level slog.Level, ok bool, err error)
- func ParseTraceparent(tp string) (trace.SpanContext, bool)
- func Start(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func StartWith(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func Traceparent(span trace.Span) string
- type Telemetry
Constants ¶
const ConversationID = attribute.Key("gen_ai.conversation.id")
ConversationID is the OpenTelemetry GenAI key for the session a span belongs to. The ADK sets it on its spans; ours use the same key so one query finds every turn of a session.
const DefaultEndpoint = "http://localhost:4318"
DefaultEndpoint is the OTLP/HTTP collector address from the OpenTelemetry spec. The Go exporters would otherwise default to https, which local collectors don't serve.
const ServiceName = "blitz"
ServiceName identifies Blitz in exported telemetry.
Variables ¶
This section is empty.
Functions ¶
func OpenLog ¶
func OpenLog(cfg config.LogConfig, r *redact.Redactor, extra ...slog.Handler) (*slog.Logger, io.Closer, error)
OpenLog returns a logger writing JSON lines to cfg.Dir (secrets masked) and to each extra handler (e.g. Telemetry.LogHandler), plus a func that flushes and closes the file. With level "off" only the extra handlers receive records, at info level.
func ParseLevel ¶
ParseLevel maps a config level to slog; ok is false for "off".
func ParseTraceparent ¶
func ParseTraceparent(tp string) (trace.SpanContext, bool)
ParseTraceparent decodes a W3C traceparent into a remote span context.
func Start ¶
func Start(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
Start begins a span on the current global provider (a no-op with telemetry off). Attributes must not carry content (prompts, file text, arguments): use sizes, names and outcomes.
func StartWith ¶
func StartWith(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartWith is Start with arbitrary span options, e.g. trace.WithLinks.
func Traceparent ¶
Traceparent encodes a span's context in W3C Trace Context form, or "" when the span is not recording a real trace (telemetry off).
Types ¶
type Telemetry ¶
type Telemetry struct {
// contains filtered or unexported fields
}
Telemetry owns the OpenTelemetry providers. A nil *Telemetry is valid and does nothing.
func NewTelemetry ¶
func NewTelemetry(cfg config.TelemetryConfig, version string, r *redact.Redactor, spanExp sdktrace.SpanExporter, logExp sdklog.Exporter) *Telemetry
NewTelemetry installs global providers exporting through the given exporters (content filtering and masking still apply). StartTelemetry uses it with OTLP/HTTP exporters; embedders and tests can pass their own. Install telemetry once per process: the ADK binds its tracer to the first global provider, so spans from later providers would miss the ADK's.
func StartTelemetry ¶
func StartTelemetry(ctx context.Context, cfg config.TelemetryConfig, version string, r *redact.Redactor) (*Telemetry, error)
StartTelemetry installs global trace and log providers exporting over OTLP/HTTP when cfg.Enabled; otherwise it returns nil. Export happens on the SDK's batch goroutines, so instrumented code only enqueues.
func (*Telemetry) LogHandler ¶
LogHandler returns an slog handler that sends records to the collector, or nil when telemetry is off.