Skip to content

feat(agent): add telemetry to TypeScript agent SDK#852

Merged
sarinali merged 2 commits intotrycua:mainfrom
sarinali:feat/typescript-sdk-telemetry
Mar 2, 2026
Merged

feat(agent): add telemetry to TypeScript agent SDK#852
sarinali merged 2 commits intotrycua:mainfrom
sarinali:feat/typescript-sdk-telemetry

Conversation

@sarinali
Copy link
Contributor

@sarinali sarinali commented Jan 19, 2026

Summary

Adds PostHog telemetry to the @trycua/agent TypeScript package for parity with the Python SDK. This enables tracking of SDK usage, agent client lifecycle, and request metrics.

Events Added

Event Trigger Key Properties
module_init Package import module: "agent", version, node_version
agent_client_initialized new AgentClient() session_id, connection_type, has_api_key
agent_request_start responses.create() called session_id, request_id, model, has_computer_kwargs, has_agent_kwargs
agent_request_end Successful response duration_ms, status, num_messages, prompt_tokens, completion_tokens, total_tokens, response_cost
agent_request_error Request failure error_type, error_message (truncated)

Error Classification

Errors are automatically classified into types:

  • timeout - Request timeout/abort
  • http_error - HTTP status errors
  • parse_error - JSON parsing errors
  • network - Network/connection errors
  • peer_error - WebRTC peer errors
  • unknown - Other errors

Files Changed

  • libs/typescript/agent/src/index.ts - Added module_init event on import
  • libs/typescript/agent/src/client.ts - Added telemetry to AgentClient class

Parity with Python SDK

Python Event TypeScript Equivalent
module_init module_init
agent_session_start agent_client_initialized
agent_run_start agent_request_start
agent_run_end agent_request_end
agent_usage Included in agent_request_end

Test plan

  • Build passes (pnpm build)
  • Telemetry events emit correctly (tested with mock endpoint)
  • Verify events appear in PostHog EU

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added comprehensive telemetry and session tracking for agent operations.
    • Improved error classification and tracking for better diagnostics.
  • API Changes

    • Introduced new responses member for unified request handling.
    • Expanded type definitions exports for enhanced TypeScript support.

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>
@vercel
Copy link
Contributor

vercel bot commented Jan 19, 2026

@sarinali is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Contributor

vercel bot commented Jan 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Jan 19, 2026 7:17am

Request Review

@@ -34,15 +48,87 @@ export class AgentClient {
};

private async sendRequest(request: AgentRequest): Promise<AgentResponse> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 20abd9b and 80a6d18.

📒 Files selected for processing (2)
  • libs/typescript/agent/src/client.ts
  • libs/typescript/agent/src/index.ts
 __________________________________________________________
< Keep your friends close, but your code reviewers closer. >
 ----------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sarinali sarinali merged commit 94df729 into trycua:main Mar 2, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants