feat(node): Add Vercel AI v7 tracing-channel support#21584
Conversation
Co-Authored-By: ChatGPT <codex@openai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
size-limit report 📦
|
Co-Authored-By: ChatGPT <codex@openai.com>
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
|
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! |

Adds Vercel AI SDK v7 tracing support by subscribing to
node:diagnostics_channel.tracingChannel('ai:telemetry')and mapping those lifecycle messages to Sentrygen_aispans.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