R6 class for logging events in a structured format (JSON).
trace_idCurrent trace ID for the session.
pricing_tablePricing for common models (USD per 1M tokens).
new()Initialize Telemetry
Telemetry$new(trace_id = NULL)trace_idOptional trace ID. If NULL, generates a random one.
log_event()Log an event
Telemetry$log_event(type, ...)typeEvent type (e.g., "generation_start", "tool_call").
...Additional fields to log.
as_hooks()Create hooks for telemetry
Telemetry$as_hooks()A HookHandler object pre-configured with telemetry logs.
calculate_cost()Calculate estimated cost for a generation result
Telemetry$calculate_cost(result, model_id = NULL)resultThe GenerateResult object.
model_idOptional model ID string. if NULL, tries to guess from context (not reliable yet, passing in log_event might be better).
Estimated cost in USD, or NULL if unknown.
clone()The objects of this class are cloneable with this method.
Telemetry$clone(deep = FALSE)deepWhether to make a deep clone.