fix(server-utils): Record Vercel AI experimental_telemetry.metadata on gen_ai spans - #24721
Conversation
size-limit report 📦
|
JPeer264
left a comment
There was a problem hiding this comment.
Implementation LGTM. However I'm not sure if we should send vercel.ai specific attributes. I added @andreiborza and @RulaKhaled who know more about status quo on these fields and if we should (re-)add them
RulaKhaled
left a comment
There was a problem hiding this comment.
Also lgtm. I’d bring this up in the agent tracing channel before merging, vercel.ai.telemetry.metadata.* attributes aren’t in @sentry/conventions, they probably can’t be convention constants but maybe we could register a prefix
| const baseAttributes: Record<string, string | number | boolean> = { | ||
| const baseAttributes: SpanAttributes = { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN, | ||
| ...telemetryMetadataAttributes(event.telemetryMetadata), |
There was a problem hiding this comment.
I wonder if this should be gated on recordInputs or dataCollection.genAI
e652f6b to
aea4552
Compare
Good call! Pinged them for input. |
|
👋 @mydea — Please review this PR when you get a chance! |
|
👋 @andreiborza — Please review this PR when you get a chance! |
RulaKhaled
left a comment
There was a problem hiding this comment.
Could you add the prefix to our conventions please?
PR open: getsentry/sentry-conventions#662 |
e5e058e to
94d0f9e
Compare
The Vercel AI integration in sentry-javascript records the `experimental_telemetry.metadata` of an AI SDK call as `vercel.ai.telemetry.metadata.<key>` span attributes. SDK v10 did this through the AI SDK's own OTel spans. A fix in v11 restores it for `ai` 4 to 6 (getsentry/sentry-javascript#24721). The type is `any`. The AI SDK allows strings, numbers, booleans and arrays of these as metadata values, and the SDK sends them unchanged. The schema allows only one type per attribute, so `any` is the only type that covers all of these values. The docs content schema did not accept `any`, though `schemas/attribute.schema.json` allows it, as of #273. No attribute used `any` before. Related: getsentry/sentry-javascript#24721 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
94d0f9e to
aadceaa
Compare
… on gen_ai spans v10 got `vercel.ai.telemetry.metadata.<key>` attributes from the AI SDK's own OTel spans. In v11, `ai` 4 to 6 go through the orchestrion subscriber, which never read `metadata`, so v11 dropped it. The orchestrion subscriber now passes the metadata to the channel subscriber, which sets it as span attributes when each span starts. The `invoke_agent`, `generate_content` and `embeddings` spans get the attributes, and `execute_tool` spans don't. This matches the AI SDK, which leaves metadata off its `ai.toolCall` spans. Values are cast to string, as discussed in the linked sentry-conventions PR. If this causes a problem we can revisit, but all extant examples found in the wild are strings already, so it is likely safe, and extremely cheap. fixes JS-3800 fixes #24720 Re: #24706 Re: getsentry/sentry-conventions#662 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
aadceaa to
131bd44
Compare
…662) The Vercel AI integration in sentry-javascript records the `experimental_telemetry.metadata` of an AI SDK call as `vercel.ai.telemetry.metadata.<key>` span attributes. SDK v10 did this through the AI SDK's own OTel spans. A fix in v11 restores it for `ai` 4 to 6 (getsentry/sentry-javascript#24721). The type is `string`. The AI SDK also allows numbers, booleans and arrays as metadata values, but in practice users pass strings. SDKs convert other values to strings. The attribute stays open-ended on purpose, because the AI SDK does not define the metadata keys. Related: getsentry/sentry-javascript#24721 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
v10 got
vercel.ai.telemetry.metadata.<key>attributes from the AI SDK's own OTel spans. In v11,ai4 to 6 go through the orchestrion subscriber, which never readmetadata, so v11 dropped it.The orchestrion subscriber now passes the metadata to the channel subscriber, which sets it as span attributes when each span starts. The
invoke_agent,generate_contentandembeddingsspans get the attributes, andexecute_toolspans don't. This matches the AI SDK, which leaves metadata off itsai.toolCallspans.Values are cast to string, as discussed in the linked sentry-conventions PR. If this causes a problem we can revisit, but all extant examples found in the wild are strings already, so it is likely safe, and extremely cheap.
fixes JS-3800
fixes #24720
Re: #24706
Re: getsentry/sentry-conventions#662