Repository navigation
feat(server-utils): Record AI SDK v7 runtime and tool context on Vercel AI spans - #25774
Conversation
size-limit report 📦Compared: 387e28d (PR test merge using develop at b63640b) Against: b63640b (develop) · base run #64512 ✅ Baseline matches: this diff contains only this PR's changes.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7dcc279. Configure here.
Optional E2E testsSome optional checks were not successful. They do not block the merge. 16 not successful, 35 successful. See the run.
Successful checks
|
andreiborza
left a comment
There was a problem hiding this comment.
LGTM just one casing change request and adding these to conventions 🙏
Removing the approval so we don't accidentally merge this before sentry conventions are in.
|
@andreiborza I added a PR to sentry-conventions for the fields being added here, but there are a few others in that file from 3bfeb64 which are also not tracked in sentry-conventions. I think the move is land this and post a follow-up issue to clean those up? What do you think? |
…756) * feat(attributes): Add Vercel AI runtime and tool context attributes Add `vercel.ai.settings.context.<key>` and `vercel.ai.tool_call.context.<key>`. `ai` 7 removed `telemetry.metadata`. Per-call metadata now goes in `runtimeContext` and `toolsContext`. The app opts keys into telemetry with `telemetry.includeRuntimeContext` and `telemetry.includeToolsContext`. The Vercel AI integration in sentry-javascript records the included keys on gen_ai spans (getsentry/sentry-javascript#25774). The runtime context name matches `@ai-sdk/otel`, which emits `ai.settings.context.<key>`, under the usual `ai.*` to `vercel.ai.*` renaming. `@ai-sdk/otel` does not record tool context, so the tool context name uses snake_case for its fixed segments. The type is `string`, as for `vercel.ai.telemetry.metadata.<key>`. Context values can have any type, so SDKs convert them to strings. `ai` versions before 7.0.114 publish the full context on the `ai:telemetry` channel and ignore the include lists. The attributes tell SDKs to read context only from events that carry `aiVersion` (added in `ai` 7.0.154), so keys the app did not opt in are not sent. Related: getsentry/sentry-javascript#24706 --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…el AI spans On `ai` 7 the `telemetry.metadata` option is gone. Per-call metadata goes in `runtimeContext`, and the app opts keys into telemetry with `telemetry.includeRuntimeContext` (and `includeToolsContext` for tool context). The channel subscriber did not read either field, so there was no way to put request-level data on gen_ai spans. The subscriber now records each included `runtimeContext` key as `vercel.ai.settings.context.<key>` on the operation span and on its `generate_content` and `execute_tool` child spans. It records each included `toolContext` key as `vercel.ai.toolCall.context.<key>` on the `execute_tool` span. The `runtimeContext` names match `@ai-sdk/otel` (`ai.settings.context.*`) under the usual `ai.*` to `vercel.ai.*` renaming. `ai` before 7.0.114 published the full context to the channel and ignored the include lists. A filtered context looks the same as an unfiltered one, so the subscriber only reads context from events that carry `aiVersion`, which `ai` added in 7.0.154. Older 7.x versions record no context, so keys the app did not opt in never leave it. Fixes #24706 Fixes JS-3788 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Rename `vercel.ai.toolCall.context.<key>` to `vercel.ai.tool_call.context.<key>`, because fixed segments in Sentry conventions use snake_case. Record every context value as a string, to match the `string` type of both attributes in sentry-conventions. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
110c6d8 to
b2ed834
Compare

On
ai7 thetelemetry.metadataoption is gone. Per-call metadata goes inruntimeContext, and the app opts keys into telemetry withtelemetry.includeRuntimeContext(andincludeToolsContextfor tool context). The channel subscriber did not read either field, so there was no way to put request-level data on gen_ai spans.The subscriber now records each included
runtimeContextkey asvercel.ai.settings.context.<key>on the operation span and on itsgenerate_contentandexecute_toolchild spans. It records each includedtoolContextkey asvercel.ai.toolCall.context.<key>on theexecute_toolspan. TheruntimeContextnames match@ai-sdk/otel(ai.settings.context.*) under the usualai.*tovercel.ai.*renaming.aibefore 7.0.114 published the full context to the channel and ignored the include lists. A filtered context looks the same as an unfiltered one, so the subscriber only reads context from events that carryaiVersion, whichaiadded in 7.0.154. Older 7.x versions record no context, so keys the app did not opt in never leave it.Fixes #24706
Fixes JS-3788