feat(agent): add telemetry to TypeScript agent SDK#852
Conversation
Add PostHog telemetry to the @trycua/agent package for parity with the Python SDK. This enables tracking of SDK usage, agent requests, and errors. Events added: - module_init: Emitted when package is imported - agent_client_initialized: Emitted when AgentClient is created - agent_request_start: Emitted when responses.create() is called - agent_request_end: Emitted on successful response - agent_request_error: Emitted on request failure Properties tracked include session_id, request_id, model, duration, token usage, and error classification. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@sarinali is attempting to deploy a commit to the Cua Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| @@ -34,15 +48,87 @@ export class AgentClient { | |||
| }; | |||
|
|
|||
| private async sendRequest(request: AgentRequest): Promise<AgentResponse> { | |||
There was a problem hiding this comment.
nice spot to inject this! I'll have to re use this for sending data to our otel stack too and can add dashes and alerting there as well
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... 📒 Files selected for processing (2)
✏️ Tip: You can disable in-progress messages and the fortune message in your review settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Summary by CodeRabbit
New Features
API Changes
responsesmember for unified request handling.