Skip to content

feat(node): Add Vercel AI v7 tracing-channel support#21584

Open
sergical wants to merge 2 commits into
developfrom
feat/vercel-ai-v7-tracing-channel
Open

feat(node): Add Vercel AI v7 tracing-channel support#21584
sergical wants to merge 2 commits into
developfrom
feat/vercel-ai-v7-tracing-channel

Conversation

@sergical

Copy link
Copy Markdown
Member

Adds Vercel AI SDK v7 tracing support by subscribing to node:diagnostics_channel.tracingChannel('ai:telemetry') and mapping those lifecycle messages to Sentry gen_ai spans.

The existing OTel span processor path remains in place for AI SDK v3-v6. The new v7 coverage verifies span hierarchy, PII gating, streaming, embeddings, rerank, and tool errors.

Refs vercel/ai#15660

Co-Authored-By: ChatGPT <codex@openai.com>
@sergical sergical marked this pull request as ready for review June 16, 2026 22:38
@sergical sergical requested a review from a team as a code owner June 16, 2026 22:38
@sergical sergical requested review from JPeer264 and mydea and removed request for a team June 16, 2026 22:38

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7d6805c. Configure here.

Comment thread packages/core/src/tracing/vercel-ai/tracing-channel.ts
Comment thread packages/core/src/tracing/vercel-ai/tracing-channel.ts
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.4 kB - -
@sentry/browser - with treeshaking flags 25.84 kB - -
@sentry/browser (incl. Tracing) 45.7 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.94 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.5 kB - -
@sentry/browser (incl. Tracing, Replay) 84.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.53 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.61 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.3 kB - -
@sentry/browser (incl. Feedback) 44.56 kB - -
@sentry/browser (incl. sendFeedback) 32.2 kB - -
@sentry/browser (incl. FeedbackAsync) 37.31 kB - -
@sentry/browser (incl. Metrics) 28.47 kB - -
@sentry/browser (incl. Logs) 28.71 kB - -
@sentry/browser (incl. Metrics & Logs) 29.4 kB - -
@sentry/react 29.2 kB - -
@sentry/react (incl. Tracing) 48 kB - -
@sentry/vue 32.42 kB - -
@sentry/vue (incl. Tracing) 47.59 kB - -
@sentry/svelte 27.42 kB - -
CDN Bundle 29.79 kB - -
CDN Bundle (incl. Tracing) 48.2 kB - -
CDN Bundle (incl. Logs, Metrics) 31.33 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.62 kB - -
CDN Bundle (incl. Tracing, Replay) 85.52 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.62 kB - -
CDN Bundle - uncompressed 88.59 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.8 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.77 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.12 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.67 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.31 kB - -
@sentry/nextjs (client) 50.45 kB - -
@sentry/sveltekit (client) 46.12 kB - -
@sentry/core/server 78.44 kB +3.11% +2.36 kB 🔺
@sentry/core/browser 63.22 kB - -
@sentry/node-core 61.72 kB - -
@sentry/node 130.87 kB +1.72% +2.2 kB 🔺
@sentry/node - without tracing 74.1 kB - -
@sentry/aws-serverless 85.46 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 174.19 kB - -
@sentry/cloudflare (withSentry) 435.41 kB - -

View base workflow run

Co-Authored-By: ChatGPT <codex@openai.com>
Comment on lines +352 to +362
const toolName = attributes[GEN_AI_TOOL_NAME_ATTRIBUTE];
const parentSpanId = spanToJSON(span).parent_span_id;
if (typeof toolName !== 'string' || !parentSpanId) {
return;
}

const description = toolDescriptionMap.get(parentSpanId)?.get(toolName);
if (description) {
span.setAttribute(GEN_AI_TOOL_DESCRIPTION_ATTRIBUTE, description);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Tool description lookup fails due to a key mismatch. Descriptions are stored by the step span's ID but retrieved using the executeTool span's parent ID, which may differ.
Severity: MEDIUM

Suggested Fix

To resolve the key mismatch, ensure the storage and lookup mechanisms use the same span ID. One approach is to store descriptions in rememberToolDescriptions using the languageModelCall span's own ID, not its parent's. This way, if executeTool is a child of languageModelCall, its parent ID will correctly match the key used for storage.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/core/src/tracing/vercel-ai/tracing-channel.ts#L351-L362

Potential issue: Tool descriptions are stored in a map keyed by the `languageModelCall`
span's parent ID, which is assumed to be the `step` span's ID. However, when an
`executeTool` span is created, the description is looked up using the `executeTool`
span's own parent ID. If the `executeTool` span is created as a child of the
`languageModelCall` span (a likely scenario depending on message timing), its parent ID
will be the `languageModelCall` span's ID, not the `step` span's ID. This key mismatch
will cause the lookup to fail, and tool descriptions will silently not be applied to the
`executeTool` spans.

Also affects:

  • packages/core/src/tracing/vercel-ai/tracing-channel.ts:343~350

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this one is a false positive for the current AI SDK v7 tracing flow. languageModelCall is wrapped only around the provider call and finishes before tool execution starts; executeTool is opened later inside the still-active step tracing-channel scope, so its parent_span_id is the step span id. The v7 integration test asserts this parentage and the description lookup (execute_tool getWeather parented to step 0 and carrying gen_ai.tool.description).

@mydea

mydea commented Jun 17, 2026

Copy link
Copy Markdown
Member

I basically forked and adjusted this PR here: #21613 with some changes, esp. around tests etc. to ensure we are compatible with v6 spans here!

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