Documentation
¶
Overview ¶
Package telemetry defines the flyedge protection-telemetry seam. It is explicit and injectable: the Guard records an Event per policy check into whatever Telemetry you install, and Report() returns a Summary you print if and when you want — the deliberate replacement for the Python SDK's auto-printed "PROTECTION SUMMARY". The default (in-memory Recorder) needs no wiring; a cloud/OTel sink is opt-in.
Index ¶
Constants ¶
const ( EventProtection = "protection_event" // a policy-check outcome (allow/deny/warn) EventLLMIO = "llm_io" // a model call: model/provider/tokens/latency (+audit) EventToolIO = "tool_io" // a tool call: name/args/result EventSessionStart = "session_start" // agent session opened EventSessionSummary = "session_summary" // agent session ended (rolled-up stats in Data) )
Event types prism's telemetry handler recognizes (event_type → activity_type). An empty Type is treated as EventProtection (a policy check).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batched ¶
type Batched struct {
// contains filtered or unexported fields
}
Batched is a cloud telemetry sink: it records events locally (so Report still works) AND buffers them for periodic delivery to the gateway on an OWNED goroutine, flushed on Close. This is the explicit lifecycle the Python SDK does with fire-and-forget daemon threads — here it's owned and stopped deterministically.
func NewBatched ¶
NewBatched starts a batcher that flushes every interval (min 1s). Call Close to flush + stop.
type Event ¶
type Event struct {
Type string // event_type; "" ⇒ protection_event
Stage string
Action string
Reason string
Model string
Provider string
Operation string
Name string // span / tool name
LatencyMS float64
// InputTokens is the provider-reported UNCACHED input count. Cache reads/writes are
// reported separately below and are also input tokens — providers split them because they
// price differently, not because the model didn't process them. The wire carries the sum;
// see toWire.
InputTokens int64
OutputTokens int64
TotalTokens int64
// Cache token counts, when the provider reports them (Anthropic prompt caching). These
// dominate real usage for long-running coding sessions: a turn commonly shows 2 uncached
// input tokens against ~380k cache reads, so omitting them understates input by orders of
// magnitude.
CacheReadTokens int64
CacheWriteTokens int64
Streaming *bool // set on streamed model calls
Err string
OccurredAt time.Time
// SessionID / RequestID correlate this record with the agent's other telemetry
// and prism's /check record for the same session. Sourced from CheckRequest.
SessionID string
RequestID string
// EndpointID / InstanceKey attribute this record to the endpoint-agent instance that
// produced it — the durable device and the (agent, repository) identity a sensor resolves.
// Both empty for a plain agent call; the platform joins on them when present.
EndpointID string
InstanceKey string
// TraceID / SpanID / ParentSpanID place this record in prism's lifecycle span
// tree (W3C ids). Empty ⇒ prism treats it as unparented.
TraceID string
SpanID string
ParentSpanID string
// AgentFramework + audit payloads + arbitrary Data (session/protection events).
AgentFramework string
RequestFull string
ResponseFull string
Data map[string]any
}
Event is one telemetry record. For a policy check (the default — Type=="" or EventProtection) Action is the normalized decision and Err is set when the enforcement call itself failed. Rich types (llm_io/tool_io/session_*) carry the model/tool/session fields below and are NOT counted as checks in Summary.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is the default in-memory telemetry: thread-safe aggregation, no I/O. Report reflects everything recorded so far.
type Sender ¶
Sender ships a serialized FlyedgeTelemetryBatch to the gateway (/v1/flyedge/telemetry). The Guard wires one backed by a signed POST; tests inject a fake.