telemetry

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package telemetry provides the metrics of tool calls: a call counter by tool and outcome, a duration histogram by tool, and the audit events dropped, as OpenTelemetry instruments on a meter provider of their own, served in the Prometheus exposition format at /metrics. Hosts that need the metrics elsewhere read them from the Exporter's registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogHooks

func LogHooks(logger *slog.Logger) *hook.Hooks

LogHooks returns hooks that emit one structured log line per tool failure, carrying the decision ID so log lines correlate with the MCP response, the audit event, and the trace span of the same call.

func Outcome

func Outcome(err error) string

Outcome classifies a tool error as a stable metric label: "" error is OK, governed rejections use their Denial code, infrastructure rejections use dedicated values, and everything else is INTERNAL (details stay in logs).

Types

type Metrics

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

Metrics records tool calls and serves them. The zero value is not usable; construct with NewMetrics.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics returns an empty collector. It cannot fail with the instruments it declares; an error would be a bug in this package.

func (*Metrics) Hooks

func (m *Metrics) Hooks() *hook.Hooks

Hooks returns lifecycle hooks that record one counter increment and one duration observation per tool call. Compose with other hooks via hook.Join.

func (*Metrics) Registry added in v0.1.13

func (m *Metrics) Registry() *prometheus.Registry

Registry is the Prometheus registry the metrics are exported to, for a host serving them alongside its own.

func (*Metrics) ServeHTTP

func (m *Metrics) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP writes the metrics in the Prometheus text exposition format.

func (*Metrics) SetAuditDropped

func (m *Metrics) SetAuditDropped(read func() int64)

SetAuditDropped installs a live reader for the audit drop counter (e.g. audit.AsyncAuditor.Dropped), sampled at scrape time. Set it before the first scrape.

func (*Metrics) Shutdown added in v0.1.13

func (m *Metrics) Shutdown(ctx context.Context) error

Shutdown flushes and stops the meter provider.

Jump to

Keyboard shortcuts

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