Skip to content

Conversation

@nikas-belogolov
Copy link
Contributor

@nikas-belogolov nikas-belogolov commented Feb 1, 2026

🎯 Changes

I've encountered a problem with tracking user token usage for billing, so I've added a telemetry field for every activity and all events.

βœ… Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

πŸš€ Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features
    • Added optional telemetry support across all core AI activities (text, image, speech, transcription, video, summarization).
    • Telemetry now flows through request, progress, and completion event payloads so activity events carry telemetry data.
    • Introduced new telemetry types/interfaces for configuration.
    • Public adapter exports reorganized for a more consistent API.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

πŸ“ Walkthrough

Walkthrough

Adds telemetry types and an optional telemetry field to multiple activity option interfaces, extends BaseEventContext with telemetry, threads telemetry through event payloads across text, image, video, speech, transcription, and summarization activities, and updates adapter export shapes and a changeset.

Changes

Cohort / File(s) Summary
Core types
packages/typescript/ai/src/types.ts
Adds TelemetryMetadataValue and TelemetrySettings; adds telemetry?: TelemetrySettings to TextOptions, SummarizationOptions, ImageGenerationOptions, VideoGenerationOptions, TTSOptions, and TranscriptionOptions.
Event client
packages/typescript/ai/src/event-client.ts
Extends BaseEventContext with optional telemetry?: TelemetrySettings and imports telemetry type.
Chat activity
packages/typescript/ai/src/activities/chat/index.ts
Adds telemetry to TextActivityOptions and TextEngine; threads telemetry into text event contexts and emissions; adjusts adapter export layout and re-exports BaseTextAdapter.
Image activity
packages/typescript/ai/src/activities/generateImage/index.ts
Adds telemetry to ImageActivityOptions; forwards telemetry in image request/completion/usage events; re-exports BaseImageAdapter and updates adapter type exports.
Speech (TTS) activity
packages/typescript/ai/src/activities/generateSpeech/index.ts
Adds telemetry to TTSActivityOptions; forwards telemetry in request start/completion and result events; re-exports BaseTTSAdapter and updates type exports.
Transcription activity
packages/typescript/ai/src/activities/generateTranscription/index.ts
Adds telemetry to TranscriptionActivityOptions; forwards telemetry to adapter and in request/completion events; re-exports BaseTranscriptionAdapter and updates type exports.
Video activity
packages/typescript/ai/src/activities/generateVideo/index.ts
Adds telemetry to VideoActivityBaseOptions; refactors getVideoJobStatus signature to VideoStatusOptions<TAdapter> and threads telemetry through status request/completion events; re-exports BaseVideoAdapter.
Summarize activity
packages/typescript/ai/src/activities/summarize/index.ts
Adds telemetry to SummarizeActivityOptions; threads telemetry through streaming and non-streaming flows and emits it in summarize request events; re-exports BaseSummarizeAdapter.
Changeset
.changeset/beige-colts-design.md
Adds changeset noting a minor version bump and "Added telemetry field to activities and events".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • AlemTuzlak
  • jherr

Poem

πŸ‡ Hopping through events with telemetry cheer,

I carry small traces of where things appear.
From text and from image to video and voice,
I stitch little footprints β€” a lightweight choice.
Observe every hop, let observability rejoice!

πŸš₯ Pre-merge checks | βœ… 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title mentions 'opentelemetry support' but the actual changes add a 'telemetry field' for observability and token usage tracking, which is broader than just OpenTelemetry support. Consider revising the title to be more specific about what telemetry support is being added (e.g., 'Add telemetry field to activities and events for observability').
βœ… Passed checks (2 passed)
Check name Status Explanation
Description check βœ… Passed The description follows the template with all required sections completed: changes explained, contributing guide and testing confirmed, and changeset generated.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/typescript/ai/src/activities/generateVideo/index.ts (1)

168-181: ⚠️ Potential issue | 🟑 Minor

Add telemetry events to generateVideo function to match other activities.

The generateVideo function (lines 168-181) doesn't emit video:request:started and video:request:completed events, unlike generateImage and summarize which emit telemetry for tracking. Additionally, the function accepts a telemetry parameter via VideoActivityBaseOptions but doesn't use it. Emit telemetry events and pass the telemetry data to maintain consistency with other activities.

🧹 Nitpick comments (1)
packages/typescript/ai/src/types.ts (1)

3-8: Consider adding JSDoc for expected metadata keys.

The Telemetry interface uses Record<string, any> which provides flexibility but offers no guidance on expected keys. Since this is for billing/token tracking, consider documenting common metadata keys users should provide.

πŸ“ Suggested documentation improvement
 /**
  * Telemetry data for tracking and debugging.
+ *
+ * `@example`
+ * ```ts
+ * telemetry: {
+ *   metadata: {
+ *     userId: 'user-123',
+ *     sessionId: 'session-456',
+ *     billingAccount: 'acct-789'
+ *   }
+ * }
+ * ```
  */
 export interface Telemetry {
+  /**
+   * Arbitrary key-value pairs for tracking context.
+   * Common keys: userId, sessionId, billingAccount, environment, etc.
+   */
   metadata: Record<string, any>
 }

@nikas-belogolov nikas-belogolov changed the title Feat: telemetry Feat: telemetry field for better observability Feb 2, 2026
@nx-cloud
Copy link

nx-cloud bot commented Feb 2, 2026

View your CI Pipeline Execution β†— for commit 08d1fef

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 2m 51s View β†—
nx run-many --targets=build --exclude=examples/** βœ… Succeeded 1m 13s View β†—

☁️ Nx Cloud last updated this comment at 2026-02-02 15:13:20 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@259

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@259

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@259

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@259

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@259

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@259

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@259

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@259

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@259

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@259

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@259

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@259

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@259

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@259

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@259

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@259

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@259

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@259

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@259

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@259

commit: 08d1fef

@nikas-belogolov nikas-belogolov marked this pull request as draft February 2, 2026 20:40
@nikas-belogolov nikas-belogolov changed the title Feat: telemetry field for better observability Feat: opentelemetry support Feb 2, 2026
@nikas-belogolov nikas-belogolov changed the title Feat: opentelemetry support [WIP] Feat: opentelemetry support Feb 2, 2026
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.

1 participant