TelemetryEvent is the SDK’s primitive for product telemetry — user actions, tool calls, agent
decisions, anything you’d send to a product analytics tool. Events are pushed independently of
trajectories, and can be correlated to them via trace_id (see
Linking Events to Trajectories).
Quickstart
Telemetry ingestion uses the generatedClient; no provider initialization is required.
Constructing Events
TelemetryEvent is a frozen dataclass. Only event_type and session_id are required; every
other field has a sensible default.
Idempotency
event_id is the idempotency key. The default UUID4 means re-runs of the same code produce
different IDs (and the backend will accept both as separate events).
For at-least-once delivery pipelines — webhooks, retries, replay from a queue — set event_id
deterministically from your own primary key so duplicate pushes are coalesced server-side:
event_id is a no-op on the backend.
Ingesting Events
ingest_events(client, events) validates events locally and ingests valid events in bounded
chunks through the generated API client.
chunk_size must be an integer greater than zero. Passing another type raises TypeError; zero
or a negative integer raises ValueError.
The call returns a TelemetryIngestSummary:
Invalid events do not poison a whole batch. Missing fields, invalid fields, non-mapping events,
and values that cannot be serialized as JSON are excluded locally and reported in
result.failures; backend failures are appended to the same list.Producing Events via TraceContext
When you’re already inside aTraceContext (the recommended path for SDK-instrumented agent
runs), use trace.event(...) so events automatically inherit the trace_id:
TraceContext.event(...) sets session_id = trace_id automatically. Override either via the
keyword arguments if you need a different grouping.
See Linking Events to Trajectories for the full
workflow, including trajectory.lib.upload_trace() which uploads a trajectory and ingests correlated events
in one atomic call.
Related
Linking Events to Trajectories
The
trace_id correlation story end-to-end.API Reference
Full signatures for
ingest_events, TelemetryEvent, and TelemetryIngestSummary.