Documentation
¶
Index ¶
- func Bool(v bool) *bool
- func ContextWithSpan(ctx context.Context, span InteractionSpan) context.Context
- func GenerateSpanID() string
- func GenerateTraceID() string
- func Int(v int) *int
- func RenderPrometheus(snap PrometheusSnapshot, stats RuntimeStats) string
- func ValidLowerHex(v string, n int) bool
- func ValidSpanID(v string) bool
- func ValidTraceID(v string) bool
- type ACPExtension
- type ACPSummary
- type ACPUsageEvent
- type AgentAttribution
- type AgentAttributor
- type AttributionFilter
- type BreakdownOptions
- type BreakdownResponse
- type Config
- type EventListOptions
- type EventListResponse
- type EventSink
- type InMemorySink
- type InteractionDimensions
- type InteractionEvent
- type InteractionObserver
- type InteractionOutcome
- type InteractionSpan
- type LLMExtension
- type LLMSummary
- type LLMUsageEvent
- type MCPExtension
- type MCPSummary
- type MCPUsageEvent
- type NoopObserver
- type NoopSpan
- type Observer
- type Pipeline
- type PrometheusProvider
- type PrometheusSnapshot
- type QueryService
- type RuntimeStats
- type SQLDBProvider
- type SeriesResponse
- type Summary
- type SummaryOptions
- type TimeseriesOptions
- type UsageService
- func (s *UsageService) AttachPrometheus(p PrometheusProvider)
- func (s *UsageService) Attribution() *AgentAttribution
- func (s *UsageService) Close() error
- func (s *UsageService) DroppedEvents() uint64
- func (s *UsageService) Observer() InteractionObserver
- func (s *UsageService) Prometheus() PrometheusProvider
- func (s *UsageService) Query() QueryService
- func (s *UsageService) Start()
- func (s *UsageService) WriteFailures() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithSpan ¶
func ContextWithSpan(ctx context.Context, span InteractionSpan) context.Context
func GenerateSpanID ¶
func GenerateSpanID() string
func GenerateTraceID ¶
func GenerateTraceID() string
func RenderPrometheus ¶
func RenderPrometheus(snap PrometheusSnapshot, stats RuntimeStats) string
RenderPrometheus formats a snapshot plus pipeline health counters as Prometheus text exposition (version 0.0.4).
func ValidLowerHex ¶
ValidLowerHex reports whether v is exactly n lowercase hex characters. Unlike ValidTraceID and ValidSpanID it permits the all-zero form, which is legal for traceparent fields that are not ids.
func ValidSpanID ¶
ValidSpanID reports whether v is a W3C span id: 16 lowercase hex characters, not all zeroes. It rejects uppercase for the same reason as ValidTraceID.
func ValidTraceID ¶
ValidTraceID reports whether v is a W3C trace id: 32 lowercase hex characters, not all zeroes. Uppercase is rejected rather than normalized, because a caller that sends it is not speaking the format the gateway echoes back.
Types ¶
type ACPExtension ¶
type ACPSummary ¶
type ACPUsageEvent ¶
type AgentAttribution ¶
type AgentAttribution struct {
// contains filtered or unexported fields
}
AgentAttribution is a settable holder for an AgentAttributor. The metrics pipeline (and therefore the observer) is constructed before the agent manager exists, so the concrete attributor is injected later via Set without rebuilding the observer.
func NewAgentAttribution ¶
func NewAgentAttribution() *AgentAttribution
func (*AgentAttribution) ResolveAgentID ¶
func (a *AgentAttribution) ResolveAgentID(routeID, serviceID, sessionID string) (string, bool)
ResolveAgentID delegates to the installed attributor, returning ok=false when none is installed.
func (*AgentAttribution) Set ¶
func (a *AgentAttribution) Set(attr AgentAttributor)
Set installs (or replaces) the active attributor. A nil attributor is ignored.
type AgentAttributor ¶
type AgentAttributor interface {
ResolveAgentID(routeID, serviceID, sessionID string) (string, bool)
}
AgentAttributor maps an originating route/service/session back to a single agent id for write-time usage attribution. It is implemented by the agent control-plane layer and consumed here so the lower layers never depend on pkg/agent (the dependency arrow stays pkg/agent -> runtime). It returns ok=false when the mapping is empty or ambiguous, in which case the agent id is left empty.
type AttributionFilter ¶
AttributionFilter selects events that belong to one agent. Write-time agent_id stamping is the primary signal, but it cannot cover events written before the agent existed, before the agent_id column existed, or while the route/service was bound to a different agent. The filter therefore matches the durable agent_id tag OR a route/service the agent currently owns, so per-agent reads (interactions, usage, activity, health) fall back to the route/service mapping for untagged-but-mappable events. An empty filter matches nothing.
ACPServiceIDs is intentionally ACP-only: the ACP runtime service is bound by at most one agent (P0 one-runtime-one-agent), so it is the only unambiguous service-level fallback. MCP service resources carry no uniqueness constraint and are recovered through RouteIDs instead. The query layer keeps this arm ACP-scoped so a same-named MCP service is never matched.
func (*AttributionFilter) IsEmpty ¶
func (f *AttributionFilter) IsEmpty() bool
IsEmpty reports whether the filter carries no selector at all.
type BreakdownOptions ¶
type BreakdownResponse ¶
type Config ¶
type Config struct {
RetentionDays int `json:"retention_days,omitempty"`
MaxAgentDepth int `json:"max_agent_depth,omitempty"`
}
func (Config) Normalized ¶
type EventListOptions ¶
type EventListResponse ¶
type InMemorySink ¶
func (*InMemorySink) Enqueue ¶
func (s *InMemorySink) Enqueue(v any) bool
type InteractionDimensions ¶
type InteractionDimensions struct {
TraceID string
SpanID string
ParentSpanID string
AgentDepth int
RouteID string
RouteKind string
RouteProtocol string
VirtualKeyID string
// AgentID, when set by the caller, is stamped verbatim. When empty the
// observer attempts attribution from RouteID via the wired AgentAttributor.
AgentID string
}
type InteractionEvent ¶
type InteractionEvent struct {
EventID string
TraceID string
SpanID string
ParentSpanID string
AgentDepth int
StartedAt time.Time
FinishedAt time.Time
RouteID string
RouteKind string
RouteProtocol string
VirtualKeyID string
Success bool
StatusCode int
ErrorType string
LatencyMS int64
// AgentID is the write-time attribution tag. It is empty for non-agent
// traffic and for events whose route/service maps to zero or more than one
// agent (stamp only when unambiguous).
AgentID string
}
InteractionEvent captures fields common to every gateway interaction.
type InteractionObserver ¶
type InteractionObserver interface {
Begin(ctx context.Context, dims InteractionDimensions) (InteractionSpan, context.Context)
}
type InteractionOutcome ¶
type InteractionSpan ¶
type InteractionSpan interface {
SetExtension(v any)
AddAnnotation(key, value string)
Finish(outcome InteractionOutcome)
}
func SpanFromContext ¶
func SpanFromContext(ctx context.Context) InteractionSpan
type LLMExtension ¶
type LLMExtension struct {
LLMAPI string
APIOperation string
ProviderID string
ProviderType string
LogicalModel string
UpstreamModel string
CredentialSource string
CredentialID string
Stream *bool
InputTokens *int
OutputTokens *int
TotalTokens *int
UsageFinalized *bool
RequestToolCount *int
RequestToolNames []string
ToolCallCount *int
ToolNames []string
}
type LLMSummary ¶
type LLMSummary struct {
RequestCount int64 `json:"request_count"`
SuccessCount int64 `json:"success_count"`
FailureCount int64 `json:"failure_count"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
AvgLatencyMS int64 `json:"avg_latency_ms"`
}
type LLMUsageEvent ¶
type LLMUsageEvent struct {
InteractionEvent
LLMAPI string
APIOperation string
ProviderID string
ProviderType string
LogicalModel string
UpstreamModel string
CredentialSource string
CredentialID string
Stream bool
InputTokens int
OutputTokens int
TotalTokens int
UsageFinalized bool
RequestToolCount int
RequestToolNames []string
ToolCallCount int
ToolNames []string
}
type MCPExtension ¶
type MCPExtension struct {
RequestID string
ServiceID string
Method string
ToolName string
PresentedToolName string
ExecutedToolName string
ExecutionMode string
PolicyAction string
ResourceURI string
PromptName string
CompletionRefType string
CompletionArgument string
ArgCount *int
ResultStatus string
Cancelled *bool
ToolArgsJSON string
}
type MCPSummary ¶
type MCPUsageEvent ¶
type MCPUsageEvent struct {
InteractionEvent
RequestID string
ServiceID string
Method string
ToolName string
PresentedToolName string
ExecutedToolName string
ExecutionMode string
PolicyAction string
ResourceURI string
PromptName string
CompletionRefType string
CompletionArgument string
ArgCount int
ResultStatus string
Cancelled bool
ToolArgsJSON string
}
type NoopObserver ¶
type NoopObserver struct{}
func (NoopObserver) Begin ¶
func (NoopObserver) Begin(ctx context.Context, _ InteractionDimensions) (InteractionSpan, context.Context)
type NoopSpan ¶
type NoopSpan struct{}
func (NoopSpan) AddAnnotation ¶
func (NoopSpan) Finish ¶
func (NoopSpan) Finish(InteractionOutcome)
func (NoopSpan) SetExtension ¶
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
func NewObserver ¶
func NewObserverWithAttribution ¶
func NewObserverWithAttribution(sink EventSink, attribution *AgentAttribution) Observer
NewObserverWithAttribution wires an attribution holder so the observer stamps agent_id at Begin from the route id when the caller did not set it.
func (Observer) Begin ¶
func (o Observer) Begin(ctx context.Context, dims InteractionDimensions) (InteractionSpan, context.Context)
type PrometheusProvider ¶
type PrometheusProvider interface {
PrometheusSnapshot() PrometheusSnapshot
}
PrometheusProvider is implemented by the in-process Prometheus sink and lets the Admin API expose an O(1) /metrics scrape without re-aggregating SQLite.
type PrometheusSnapshot ¶
type PrometheusSnapshot struct {
RequestsByKind map[string]int64
FailuresByKind map[string]int64
TokensByKind map[string]int64
}
PrometheusSnapshot is a low-cardinality counter view of usage events keyed by interaction kind (llm/mcp/acp). It lives in this package so both the sink that produces it (internal/observability/pipeline) and the Admin API that renders it can share the type without an import cycle.
type QueryService ¶
type QueryService interface {
Summary() (Summary, error)
ListEvents(kind string, opts EventListOptions) (EventListResponse, error)
ListInteractions(opts EventListOptions) (EventListResponse, error)
LLMTimeseries(opts TimeseriesOptions) (SeriesResponse, error)
LLMBreakdown(opts BreakdownOptions) (BreakdownResponse, error)
MCPTimeseries(opts TimeseriesOptions) (SeriesResponse, error)
MCPBreakdown(opts BreakdownOptions) (BreakdownResponse, error)
MCPToolsSummary(opts SummaryOptions) (BreakdownResponse, error)
ACPTimeseries(opts TimeseriesOptions) (SeriesResponse, error)
ACPBreakdown(opts BreakdownOptions) (BreakdownResponse, error)
ACPSummary(opts BreakdownOptions) (BreakdownResponse, error)
InteractionsSummary(opts BreakdownOptions) (BreakdownResponse, error)
}
type RuntimeStats ¶
RuntimeStats exposes pipeline health counters for the metrics Admin API so silently dropped or failed usage writes remain observable.
type SQLDBProvider ¶
type SeriesResponse ¶
type Summary ¶
type Summary struct {
LLM LLMSummary `json:"llm"`
MCP MCPSummary `json:"mcp"`
ACP ACPSummary `json:"acp"`
}
type SummaryOptions ¶
type TimeseriesOptions ¶
type UsageService ¶
type UsageService struct {
// contains filtered or unexported fields
}
func NewUsageService ¶
func NewUsageService(pipeline Pipeline, query QueryService) *UsageService
func (*UsageService) AttachPrometheus ¶
func (s *UsageService) AttachPrometheus(p PrometheusProvider)
AttachPrometheus registers the in-process Prometheus snapshot provider so the Admin API can expose an O(1) /metrics scrape.
func (*UsageService) Attribution ¶
func (s *UsageService) Attribution() *AgentAttribution
Attribution returns the settable agent attribution holder. Callers inject the concrete attributor (the agent manager) after the gateway is bootstrapped, so the observer can stamp agent_id at write time.
func (*UsageService) Close ¶
func (s *UsageService) Close() error
func (*UsageService) DroppedEvents ¶
func (s *UsageService) DroppedEvents() uint64
func (*UsageService) Observer ¶
func (s *UsageService) Observer() InteractionObserver
func (*UsageService) Prometheus ¶
func (s *UsageService) Prometheus() PrometheusProvider
func (*UsageService) Query ¶
func (s *UsageService) Query() QueryService
func (*UsageService) Start ¶
func (s *UsageService) Start()
func (*UsageService) WriteFailures ¶
func (s *UsageService) WriteFailures() uint64