Help us shape the future of Go! Take the 2026 Go Developer Survey

observability

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureMetrics

func ConfigureMetrics(logger zerolog.Logger) (http.Handler, error)

ConfigureMetrics installs a Prometheus-backed MeterProvider and registers the GenAI client metric instruments. It returns an http.Handler that serves the metrics in Prometheus text format (mount at /metrics). Metrics are pull-based and entirely independent of the OTLP trace export — nothing is pushed to the trace backend. Safe to call once at startup.

func ConfigureOTel

func ConfigureOTel(ctx context.Context, endpoint, projectName string, token *BearerToken, logger zerolog.Logger) error

ConfigureOTel sets the global TracerProvider. When endpoint is empty, installs a no-op provider (zero overhead). Safe to call multiple times. A non-nil token is sent as a bearer header with every export.

func ContextWithSession

func ContextWithSession(ctx context.Context, sessionID, userID string) context.Context

ContextWithSession is the Go equivalent of Phoenix's setSession() — it stores session.id and user.id in baggage so the sessionBaggageProcessor stamps them onto every child span automatically. Phoenix indexes sessions on "session.id".

func RecordGenAISessionDuration

func RecordGenAISessionDuration(ctx context.Context, provider, model string, seconds float64)

RecordGenAISessionDuration records a completed voice session's wall-clock duration. No-op when not configured.

func RecordGenAITimePerOutputToken

func RecordGenAITimePerOutputToken(ctx context.Context, operation, provider, model string, seconds float64)

RecordGenAITimePerOutputToken records TPOT: mean output streaming latency per output token within a turn (output-streaming duration ÷ output token count). No-op when not configured.

func RecordGenAITimeToFirstToken

func RecordGenAITimeToFirstToken(ctx context.Context, operation, provider, model string, seconds float64)

RecordGenAITimeToFirstToken records time-to-first-token (TTFT): the latency from the end of user input to the first model output chunk. No-op when not configured.

func RecordGenAITokenUsage

func RecordGenAITokenUsage(ctx context.Context, operation, provider, model string, inputTokens, outputTokens int64)

RecordGenAITokenUsage records the gen_ai.client.token.usage histogram, split by token type ("input"/"output"). No-op when metrics are not configured.

func RecordGenAITokenUsageByModality

func RecordGenAITokenUsageByModality(ctx context.Context, operation, provider, model, tokenType, modality string, tokens int64)

RecordGenAITokenUsageByModality records the gen_ai.client.token.usage histogram split by token type ("input"/"output") AND modality ("audio"/"text"/…), so the metric reconciles to the per-modality Vertex Live billing SKUs (audio-in vs text-in vs audio-out vs text-out). tokenType is "input" or "output"; modality is the lower-cased SDK modality string. No-op when metrics are not configured or tokens <= 0.

func RecordGenAIToolDuration

func RecordGenAIToolDuration(ctx context.Context, toolName string, seconds float64)

RecordGenAIToolDuration records a tool call's execution latency, labeled by tool name (gen_ai.tool.name). No-op when not configured.

func RecordMemorySearchDuration

func RecordMemorySearchDuration(ctx context.Context, mode string, seconds float64)

RecordMemorySearchDuration records a memory search's latency, labeled by mode ("lexical" for the no-network fast path, "fused" when semantic search ran). No-op when not configured.

func RecordMemorySearchPhase

func RecordMemorySearchPhase(ctx context.Context, phase string, seconds float64)

RecordMemorySearchPhase records one phase of a semantic search ("embed" or "index"). No-op when not configured.

Types

type BearerToken

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

BearerToken sends an Authorization: Bearer header on every OTLP export. The token can arrive after the exporter starts (it is read from a Secret once the cluster cache syncs) and can change while running; until it is set, exports go out without the header and the collector decides what to do with them.

func (*BearerToken) GetRequestMetadata

func (b *BearerToken) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata implements grpc credentials.PerRPCCredentials.

func (*BearerToken) RequireTransportSecurity

func (b *BearerToken) RequireTransportSecurity() bool

RequireTransportSecurity is false: the collector is usually a cluster-local Service reached over plaintext gRPC.

func (*BearerToken) Set

func (b *BearerToken) Set(token string)

Set replaces the token.

Jump to

Keyboard shortcuts

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