telemetry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package telemetry wires amoxtli to OpenTelemetry. It exposes a shared tracer and meter under a single instrumentation scope, plus lazily-created metric instruments for the two things worth watching in a RAG library: search latency and LLM cost (call count, latency, token usage).

Instrumentation is always on but cheap: when the process has not installed a TracerProvider/MeterProvider, OpenTelemetry's global no-op providers are used and every span/measurement is discarded at near-zero cost. A consumer opts into real telemetry simply by installing the OTel SDK providers in their program; nothing in amoxtli needs to change.

Index

Constants

View Source
const (
	// AttrOperation labels an LLM operation (chat_completion, embeddings, ...).
	AttrOperation = "amoxtli.llm.operation"
	// AttrTokenKind distinguishes prompt vs. completion tokens on the token
	// counter.
	AttrTokenKind = "amoxtli.llm.token_kind"
	// AttrQueryLength is the character length of a search query (queries
	// themselves are not recorded, to avoid leaking user content).
	AttrQueryLength = "amoxtli.search.query_length"
	// AttrResultCount is the number of results returned by a search.
	AttrResultCount = "amoxtli.search.result_count"
)

Attribute keys used across amoxtli spans and metrics.

View Source
const ScopeName = "github.com/bornholm/amoxtli"

ScopeName is the instrumentation scope reported on every span and metric.

Variables

This section is empty.

Functions

func Meter

func Meter() metric.Meter

Meter returns amoxtli's shared meter from the global provider.

func Tracer

func Tracer() trace.Tracer

Tracer returns amoxtli's shared tracer from the global provider.

Types

type Instruments

type Instruments struct {
	// LLMCalls counts LLM calls, tagged by operation.
	LLMCalls metric.Int64Counter
	// LLMDuration is the LLM call latency in seconds, tagged by operation.
	LLMDuration metric.Float64Histogram
	// LLMTokens counts tokens consumed, tagged by operation and token kind.
	LLMTokens metric.Int64Counter
	// SearchDuration is the search latency in seconds.
	SearchDuration metric.Float64Histogram
	// SearchResults counts results returned across searches.
	SearchResults metric.Int64Counter
}

Instruments holds the metric instruments amoxtli records into. They are created once against the global meter; if instrument creation fails (which it should not with the no-op or a well-formed provider) the field is left nil and recording against it is silently skipped by the helpers below.

func Metrics

func Metrics() *Instruments

Metrics returns the shared, lazily-initialised metric instruments. The first call builds them against the global meter; subsequent calls return the same set. It never returns nil.

Jump to

Keyboard shortcuts

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