otel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package otel implements Surface 3 — OpenTelemetry GenAI export. It emits one span per governed model call carrying the attribute set pinned in api/v1/otel-genai.md (gen_ai.* + riskkernel.*), so a run becomes observable in whatever OTLP backend the user already runs (Grafana Tempo, SigNoz, Jaeger, Honeycomb, Datadog, …).

It is OFF unless the user configures an OTLP endpoint. RiskKernel never emits telemetry on its own — spans go only to the endpoint the user points it at. This is the only package besides internal/provider permitted outbound network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	RunID         string
	StepIndex     int32
	Provider      string
	Operation     string // e.g. "chat"
	RequestModel  string
	ResponseModel string
	MaxTokens     int
	Temperature   *float64
	PromptTokens  int64
	OutputTokens  int64
	CostUSD       float64
	Priced        bool
	FinishReason  string
	ResponseID    string

	BudgetTokensLimit      int64
	BudgetTokensRemaining  int64
	BudgetDollarsLimit     float64
	BudgetDollarsRemaining float64

	HaltReason string // empty if none
	Err        error  // non-nil if the call failed

	Start time.Time
	End   time.Time
}

Call is the data for one governed model-call span.

type Tracer

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

Tracer emits governed-call spans. The zero value and Disabled() are safe no-ops.

func Disabled

func Disabled() *Tracer

Disabled returns a no-op Tracer (used when no OTLP endpoint is configured and in tests).

func New

func New(ctx context.Context, cfg config.OTelConfig, log *slog.Logger) (*Tracer, error)

New builds a Tracer. If cfg.Endpoint is empty it returns a disabled no-op Tracer (no exporter, no network). Otherwise it wires an OTLP exporter (grpc or http) to the configured endpoint.

func NewWithProcessor

func NewWithProcessor(sp sdktrace.SpanProcessor, serviceName string) *Tracer

NewWithProcessor builds an enabled Tracer around a caller-supplied span processor — useful for custom pipelines and for tests (e.g. an in-memory span recorder).

func (*Tracer) Enabled

func (t *Tracer) Enabled() bool

Enabled reports whether spans are being exported.

func (*Tracer) RecordCall

func (t *Tracer) RecordCall(ctx context.Context, c Call)

RecordCall emits a span for one governed model call. No-op when disabled.

func (*Tracer) Shutdown

func (t *Tracer) Shutdown(ctx context.Context) error

Shutdown flushes buffered spans and releases the exporter.

Jump to

Keyboard shortcuts

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