Documentation
¶
Index ¶
- Constants
- func InitTracer(cfg config.TracingConfig) (*sdktrace.TracerProvider, func(context.Context) error, error)
- func Tracer() trace.Tracer
- type AgentMetric
- type MetricsCollector
- func (c *MetricsCollector) RecordPolicyDecision(verdict, reason string)
- func (c *MetricsCollector) RecordTokenUsage(usage TokenUsage)
- func (c *MetricsCollector) RecordToolExecution(name, agentName string, duration time.Duration, success bool)
- func (c *MetricsCollector) Reset()
- func (c *MetricsCollector) SessionMetrics(sessionKey string) *SessionMetric
- func (c *MetricsCollector) Snapshot() SystemSnapshot
- func (c *MetricsCollector) TopSessions(limit int) []SessionMetric
- type PolicyMetrics
- type PrometheusExporter
- type SessionMetric
- type SystemSnapshot
- type TokenUsage
- type TokenUsageSummary
- type ToolMetric
Constants ¶
const DefaultMaxSessions = 10000
DefaultMaxSessions is the default session map capacity before LRU eviction.
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
func InitTracer(cfg config.TracingConfig) (*sdktrace.TracerProvider, func(context.Context) error, error)
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.
Types ¶
type AgentMetric ¶
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.