observability

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSessions = 10000

DefaultMaxSessions is the default session map capacity before LRU eviction.

View Source
const TracerName = "lango"

TracerName is the instrumentation name used for Lango spans.

Variables

This section is empty.

Functions

func InitTracer added in v0.7.0

InitTracer initializes an OpenTelemetry TracerProvider based on config. Returns the provider and a shutdown function. Caller must call shutdown on application exit to flush pending spans.

func Tracer added in v0.7.0

func Tracer() trace.Tracer

Tracer returns a tracer from the global TracerProvider.

Types

type AgentMetric

type AgentMetric struct {
	Name         string
	InputTokens  int64
	OutputTokens int64
	ToolCalls    int64
}

AgentMetric aggregates metrics for a single agent.

type MetricsCollector

type MetricsCollector struct {

	// MaxSessions caps the session map size; 0 means DefaultMaxSessions.
	MaxSessions int
	// contains filtered or unexported fields
}

MetricsCollector performs thread-safe in-memory metrics aggregation.

func NewCollector

func NewCollector() *MetricsCollector

NewCollector creates a new MetricsCollector.

func (*MetricsCollector) RecordPolicyDecision added in v0.7.0

func (c *MetricsCollector) RecordPolicyDecision(verdict, reason string)

RecordPolicyDecision records a policy block or observe event. verdict is a string such as "block" or "observe".

func (*MetricsCollector) RecordTokenUsage

func (c *MetricsCollector) RecordTokenUsage(usage TokenUsage)

RecordTokenUsage records a token usage event.

func (*MetricsCollector) RecordToolExecution

func (c *MetricsCollector) RecordToolExecution(name, agentName string, duration time.Duration, success bool)

RecordToolExecution records a tool execution event.

func (*MetricsCollector) Reset

func (c *MetricsCollector) Reset()

Reset clears all collected metrics.

func (*MetricsCollector) SessionMetrics

func (c *MetricsCollector) SessionMetrics(sessionKey string) *SessionMetric

SessionMetrics returns metrics for a specific session, or nil if not found.

func (*MetricsCollector) Snapshot

func (c *MetricsCollector) Snapshot() SystemSnapshot

Snapshot returns a point-in-time copy of all metrics.

func (*MetricsCollector) TopSessions

func (c *MetricsCollector) TopSessions(limit int) []SessionMetric

TopSessions returns the top N sessions by total tokens.

type PolicyMetrics added in v0.7.0

type PolicyMetrics struct {
	Blocks   int64            `json:"blocks"`
	Observes int64            `json:"observes"`
	ByReason map[string]int64 `json:"byReason"`
}

PolicyMetrics aggregates policy decision counts.

type PrometheusExporter added in v0.7.0

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

PrometheusExporter exposes Lango metrics in Prometheus exposition format. It subscribes to EventBus events and updates counters/gauges directly.

func NewPrometheusExporter added in v0.7.0

func NewPrometheusExporter() *PrometheusExporter

NewPrometheusExporter creates a new exporter with registered metrics.

func (*PrometheusExporter) Handler added in v0.7.0

func (e *PrometheusExporter) Handler() http.Handler

Handler returns an HTTP handler for the Prometheus exposition endpoint.

func (*PrometheusExporter) SetCollector added in v0.7.0

func (e *PrometheusExporter) SetCollector(c *MetricsCollector)

SetCollector links the exporter to a MetricsCollector so it can update the tracked-sessions gauge from token usage events.

func (*PrometheusExporter) Subscribe added in v0.7.0

func (e *PrometheusExporter) Subscribe(bus *eventbus.Bus)

Subscribe wires the exporter to receive events from the EventBus.

type SessionMetric

type SessionMetric struct {
	SessionKey   string
	InputTokens  int64
	OutputTokens int64
	TotalTokens  int64
	RequestCount int64
	LastUpdated  time.Time
}

SessionMetric aggregates metrics for a single session.

type SystemSnapshot

type SystemSnapshot struct {
	StartedAt        time.Time
	Uptime           time.Duration
	TokenUsageTotal  TokenUsageSummary
	ToolExecutions   int64
	ToolBreakdown    map[string]ToolMetric
	AgentBreakdown   map[string]AgentMetric
	SessionBreakdown map[string]SessionMetric
	Policy           PolicyMetrics
}

SystemSnapshot is a point-in-time summary of system metrics.

type TokenUsage

type TokenUsage struct {
	Provider     string
	Model        string
	SessionKey   string
	AgentName    string
	InputTokens  int64
	OutputTokens int64
	TotalTokens  int64
	CacheTokens  int64
	Timestamp    time.Time
}

TokenUsage records a single token usage event.

type TokenUsageSummary

type TokenUsageSummary struct {
	InputTokens  int64
	OutputTokens int64
	TotalTokens  int64
	CacheTokens  int64
}

TokenUsageSummary aggregates token counts across all providers/models.

type ToolMetric

type ToolMetric struct {
	Name          string
	Count         int64
	Errors        int64
	TotalDuration time.Duration
	AvgDuration   time.Duration
}

ToolMetric aggregates metrics for a single tool.

Directories

Path Synopsis
Package audit records events to the existing AuditLog Ent schema.
Package audit records events to the existing AuditLog Ent schema.

Jump to

Keyboard shortcuts

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