feat(agent): add telemetry to TypeScript agent SDK #852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds PostHog telemetry to the
@trycua/agentTypeScript package for parity with the Python SDK. This enables tracking of SDK usage, agent client lifecycle, and request metrics.Events Added
module_initmodule: "agent",version,node_versionagent_client_initializednew AgentClient()session_id,connection_type,has_api_keyagent_request_startresponses.create()calledsession_id,request_id,model,has_computer_kwargs,has_agent_kwargsagent_request_endduration_ms,status,num_messages,prompt_tokens,completion_tokens,total_tokens,response_costagent_request_errorerror_type,error_message(truncated)Error Classification
Errors are automatically classified into types:
timeout- Request timeout/aborthttp_error- HTTP status errorsparse_error- JSON parsing errorsnetwork- Network/connection errorspeer_error- WebRTC peer errorsunknown- Other errorsFiles Changed
libs/typescript/agent/src/index.ts- Addedmodule_initevent on importlibs/typescript/agent/src/client.ts- Added telemetry to AgentClient classParity with Python SDK
module_initmodule_init✅agent_session_startagent_client_initialized✅agent_run_startagent_request_start✅agent_run_endagent_request_end✅agent_usageagent_request_end✅Test plan
pnpm build)🤖 Generated with Claude Code