Skip to content

Conversation

@sarinali
Copy link
Contributor

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

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

},
};

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

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