Skip to content

feat(server-runtimes): Add v7 support for vercelAiIntegration#21613

Merged
mydea merged 20 commits into
developfrom
fn/vercel-ai-v7
Jun 25, 2026
Merged

feat(server-runtimes): Add v7 support for vercelAiIntegration#21613
mydea merged 20 commits into
developfrom
fn/vercel-ai-v7

Conversation

@mydea

@mydea mydea commented Jun 17, 2026

Copy link
Copy Markdown
Member

In the latest beta release of v7 of the ai package, native tracing channel events are now emitted. This PR adds support for this and thus for instrumentation in this package.

For now, this is only implemented in node, but can also be ported to deno/bun.

A big part of this PR was making sure that the v6 tests also run for v7 to make sure this is compatible. It may need some cleanup but tests pass now. The tests are identical for v6 and v7 (just fixed some formatting stuff, moved folder, added a describe.each to run it multiple times), git just could not fully keep up with the changes so it appears bigger than it is.

Supersedes #21584

Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from ec59e1b to 21822ce Compare June 17, 2026 17:19
Comment thread packages/node/src/integrations/tracing/vercelai/index.ts Outdated
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB +0.01% +1 B 🔺
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.89 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 77.39 kB +0.14% +106 B 🔺
@sentry/core/browser 63.74 kB +0.17% +105 B 🔺
@sentry/node-core 61.51 kB +0.01% +1 B 🔺
@sentry/node 124.5 kB +1.51% +1.84 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB - -
@sentry/node - without tracing 73.55 kB +0.01% +1 B 🔺
@sentry/aws-serverless 84.33 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.31 kB - -
@sentry/cloudflare (withSentry) 446.24 kB - -

View base workflow run

@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 21822ce to d6dba4f Compare June 18, 2026 09:01
@mydea mydea marked this pull request as ready for review June 18, 2026 09:17
@mydea mydea requested a review from a team as a code owner June 18, 2026 09:17
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team June 18, 2026 09:17
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 0caa954 to 540d331 Compare June 18, 2026 14:18
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
@nicohrubec nicohrubec self-requested a review June 19, 2026 08:23
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 540d331 to f8e0817 Compare June 19, 2026 08:33
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
if (messages === undefined) {
return {};
}
return { [GEN_AI_INPUT_MESSAGES]: safeStringify(messages) };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m: While I know truncation is going away soon(tm), we should make sure we pass this through truncation logic today. The helpers are currently not exported from @sentry/core, so I think we should inline them to avoid exposing new api from core that goes way with the next major anyway.

And also once we do that, we should also record the original length of the message via GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE.

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.

hm not sure if worth it to add this today? What if we say for v7 we simply have no truncation? 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's fairly straight forward to add and we wouldn't have to document any differences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we still need truncation until we enable streamGenAiSpans by default, else we'll have users running into dropped spans/transactions again

Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 7a776ff to 63b6d82 Compare June 19, 2026 12:59
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts Outdated
@logaretm

Copy link
Copy Markdown
Member

Should we try using #21641 here?

@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 63b6d82 to 7a133b7 Compare June 22, 2026 11:28
@mydea

mydea commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

Should we try using #21641 here?

sure, we can wait for this!

in the meanwhile, I added truncation support here as well.

cleanupChildProcesses();
});

createEsmAndCjsTests(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

changed it to only run a single thing in cjs, and guarding this for node 18 where it does not work. other tests only run in esm not for simplicity.

export type { MetricOptions } from './metrics/public-api';
export { createConsolaReporter } from './integrations/consola';
export { addVercelAiProcessors } from './tracing/vercel-ai';
export { getTruncatedJsonString, shouldEnableTruncation } from './tracing/ai/utils';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are we turning on sendGenAiSpans by default now? in that case we might be fine without adding truncation saving us a breaking change since we will need to remove these exports again. alternatively we could only do the media truncation part (which will stay) and just not doing text truncation

@mydea mydea requested review from andreiborza and nicohrubec June 24, 2026 07:41
@mydea mydea marked this pull request as draft June 24, 2026 07:41
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from d233a39 to 9f1d99f Compare June 25, 2026 08:43
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts

@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.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3b3a6b1. Configure here.

Comment thread packages/server-utils/src/vercel-ai/index.ts
Comment thread packages/server-utils/src/vercel-ai/vercel-ai-dc-subscriber.ts
@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 4f7503a to 9145703 Compare June 25, 2026 11:27
// This is a no-op on versions that don't publish to the channel, so it is always safe to call.
// The factory needs the Sentry OTel context manager, which `initOpenTelemetry()` registers after `setupOnce`, so defer a tick.
// Options are passed in here rather than read back off the integration per event.
void Promise.resolve().then(() => subscribeVercelAiTracingChannel(dc.tracingChannel, options));

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: The type of dc.tracingChannel is not correctly narrowed within the Promise.then() callback, creating a potential type-safety issue that relies solely on a runtime guard.
Severity: LOW

Suggested Fix

To ensure type safety and align with patterns elsewhere in the codebase, either store dc.tracingChannel in a local variable before the promise chain or add an explicit type assertion, like subscribeVercelAiTracingChannel(dc.tracingChannel as VercelAiTracingChannelFactory, options).

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/server-utils/src/vercel-ai/index.ts#L40

Potential issue: In Node.js versions where `diagnostics_channel.tracingChannel` is
undefined (e.g., Node 18), TypeScript's type narrowing does not persist across
asynchronous boundaries. A truthiness check is performed on `dc.tracingChannel`, but it
is then used within a `Promise.resolve().then()` callback. The TypeScript compiler may
not be able to infer that `dc.tracingChannel` is still defined inside the callback,
potentially leading to a type error. While a runtime check currently prevents issues,
the code is not type-safe, unlike similar integrations in the codebase that use explicit
type assertions to resolve this ambiguity for the compiler.

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.

we guard for this now

@mydea mydea force-pushed the fn/vercel-ai-v7 branch from 9145703 to abad3a9 Compare June 25, 2026 11:33
@mydea mydea enabled auto-merge (squash) June 25, 2026 12:29
@mydea mydea merged commit 3bfeb64 into develop Jun 25, 2026
1094 of 1100 checks passed
@mydea mydea deleted the fn/vercel-ai-v7 branch June 25, 2026 13:20
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.

5 participants