Documentation
¶
Overview ¶
Package metrics turns component/run reports into telemetry. It provides concrete components.Emitter implementations; the pipeline depends only on the Emitter interface, so this package imports components and not vice versa.
v1 ships: Nop (in components), Slog (structured logs in OTel gen_ai.* vocabulary), and Aggregator (in-process rollups behind /stats). An OTel-SDK emitter and honest-metrics extras (bounce-adjusted savings, waste signals) land in P5. Each host surfaces these natively (proxy -> bifrost Prometheus/ OTel + /metrics; AuthBridge -> StatsSource).
Index ¶
- type Aggregator
- func (a *Aggregator) Component(r components.Report)
- func (a *Aggregator) RecordAddedLatency(ms float64)
- func (a *Aggregator) RecordExpand(tokens int)
- func (a *Aggregator) RecordUpstreamLatency(ms float64, bypassed bool)
- func (a *Aggregator) Run(r components.RunReport)
- func (a *Aggregator) Snapshot() Snapshot
- type Slog
- type Snapshot
- type Tee
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator keeps process-wide and per-component rollups for /stats. Savings are token-weighted (SUM saved / SUM before), the honest aggregate — not a mean of per-request percentages (rtk's lesson).
func (*Aggregator) Component ¶
func (a *Aggregator) Component(r components.Report)
func (*Aggregator) RecordAddedLatency ¶
func (a *Aggregator) RecordAddedLatency(ms float64)
RecordAddedLatency notes the wall time (ms) context-guru added to one request (normalize + pipeline + writeback). Only meaningful on the active path.
func (*Aggregator) RecordExpand ¶
func (a *Aggregator) RecordExpand(tokens int)
RecordExpand notes that `tokens` of previously-offloaded content had to be re-served (the model called expand). This is the bounce signal: it means an offload was premature, so the honest savings figure subtracts it (lean-ctx's adjusted savings).
func (*Aggregator) RecordUpstreamLatency ¶
func (a *Aggregator) RecordUpstreamLatency(ms float64, bypassed bool)
RecordUpstreamLatency notes one provider round-trip (ms), split by whether the request bypassed context-guru — so a run can compare with-CG vs baseline latency.
func (*Aggregator) Run ¶
func (a *Aggregator) Run(r components.RunReport)
func (*Aggregator) Snapshot ¶
func (a *Aggregator) Snapshot() Snapshot
Snapshot returns a point-in-time copy of the rollups.
type Slog ¶
Slog logs each component and run in the GenAI semantic-convention vocabulary.
func (Slog) Component ¶
func (s Slog) Component(r components.Report)
func (Slog) Run ¶
func (s Slog) Run(r components.RunReport)
type Snapshot ¶
type Snapshot struct {
Requests int64 `json:"requests"`
TokensBefore int64 `json:"tokens_before"`
TokensAfter int64 `json:"tokens_after"`
SavedTokens int64 `json:"saved_tokens"`
SavingsPct float64 `json:"savings_pct"`
WastedTokens int64 `json:"wasted_tokens"` // re-served via expand
Bounces int64 `json:"bounces"` // expand events
AdjustedSaved int64 `json:"adjusted_saved"` // saved - wasted (may be negative)
Components map[string]compStat `json:"components"`
// TopPassthrough names components that ran but never saved a token — dead
// weight in the pipeline, candidates to drop from the config.
TopPassthrough []string `json:"top_passthrough"`
// LLM* report the cheap (config-source) model usage the CONTEXT-GURU components
// themselves incurred (e.g. extract:code's Starlark-writer calls) — the CG
// components' OWN cost, separate from the agent. Priced externally.
LLMCalls int64 `json:"llm_calls"`
LLMInputTokens int64 `json:"llm_input_tokens"`
LLMOutputTokens int64 `json:"llm_output_tokens"`
// End-to-end latency (W7): mean ms context-guru added per request, and mean
// provider round-trip on the active vs bypassed (baseline) path — a with/without
// context-guru session-latency comparison.
AddedLatencyMsAvg float64 `json:"cg_added_ms_avg"`
UpstreamMsAvg float64 `json:"upstream_ms_avg"`
UpstreamMsAvgBypassed float64 `json:"upstream_ms_avg_bypassed"`
}
Snapshot is the JSON served at /stats. It reports both gross savings and the honest, bounce-adjusted figure, plus quality signals naming components that never earned their place (rtk's top_passthrough idea).
type Tee ¶
type Tee []components.Emitter
Tee fans a report out to several emitters.
func (Tee) Component ¶
func (t Tee) Component(r components.Report)
func (Tee) Run ¶
func (t Tee) Run(r components.RunReport)