Skip to content

fix(node): Ensure tool errors for vercelAiIntegration have correct trace connected #17132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 24, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 23, 2025

This fixes the problem that for tool errors triggered from vercel-ai integration, traces were not connected.
This seemed to happen because errors bubble up to the global unhandled rejection handler, where the span is no longer active and thus the trace cannot be connected.

This PR fixes this by attaching the active span to the error and using this in the unhandled rejection handler, if it exists.

Closes #17108

@mydea mydea self-assigned this Jul 23, 2025
Copy link
Contributor

github-actions bot commented Jul 23, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.75 kB - -
@sentry/browser - with treeshaking flags 22.33 kB - -
@sentry/browser (incl. Tracing) 39.6 kB - -
@sentry/browser (incl. Tracing, Replay) 77.77 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.58 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.47 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.57 kB - -
@sentry/browser (incl. Feedback) 40.44 kB - -
@sentry/browser (incl. sendFeedback) 28.42 kB - -
@sentry/browser (incl. FeedbackAsync) 33.33 kB - -
@sentry/react 25.49 kB - -
@sentry/react (incl. Tracing) 41.58 kB - -
@sentry/vue 28.18 kB - -
@sentry/vue (incl. Tracing) 41.4 kB - -
@sentry/svelte 23.77 kB - -
CDN Bundle 25.16 kB - -
CDN Bundle (incl. Tracing) 39.4 kB - -
CDN Bundle (incl. Tracing, Replay) 75.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.88 kB - -
CDN Bundle - uncompressed 73.42 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.83 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 230.97 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.78 kB - -
@sentry/nextjs (client) 43.61 kB - -
@sentry/sveltekit (client) 40.03 kB - -
@sentry/node-core 47.31 kB +0.18% +82 B 🔺
@sentry/node 143.93 kB +0.03% +40 B 🔺
@sentry/node - without tracing 91.4 kB +0.11% +95 B 🔺
@sentry/aws-serverless 102.85 kB +0.1% +93 B 🔺

View base workflow run

@mydea mydea marked this pull request as ready for review July 23, 2025 13:50
@@ -7,5 +7,5 @@ Sentry.init({
tracesSampleRate: 1.0,
sendDefaultPii: true,
transport: loggingTransport,
integrations: [Sentry.vercelAIIntegration({ force: true })],
Copy link
Member Author

Choose a reason for hiding this comment

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

leftover that should not be needed anymore

// So to circumvent this, we set the active span on the error object
// which is picked up by the unhandledrejection handler
if (error && typeof error === 'object') {
addNonEnumerableProperty(error, '_sentry_active_span', getActiveSpan());
Copy link
Member

Choose a reason for hiding this comment

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

fwiw addNonEnumerableProperty is really slow, but I guess in error codepaths this is fine.

cleanupChildProcesses();
});

test('should capture and send Express controller error with txn name if tracesSampleRate is 1', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

noticed this test was missing, just adding for completeness sake.

@@ -5,7 +5,7 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
transport: loggingTransport,
tracesSampleRate: 1,
tracesSampleRate: 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

this was actually not testing what the test said it would ^^

@@ -0,0 +1,50 @@
import * as Sentry from '@sentry/node';
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
Copy link
Member

Choose a reason for hiding this comment

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

:O

cursor[bot]

This comment was marked as outdated.

@mydea mydea force-pushed the fn/vercel-ai-tests branch from 3da5545 to 08659ea Compare July 24, 2025 07:36
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Transaction Sampling Test Fails

The test removes .ignore('transaction'), causing it to expect transaction events. This conflicts with the server's tracesSampleRate: 0 configuration, which prevents transaction sampling. Consequently, the test fails because no transaction event is generated, despite the test's intent to verify behavior when tracesSampleRate is 0.

dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts#L8-L14

test('should capture and send Express controller error with txn name if tracesSampleRate is 0', async () => {
const runner = createRunner(__dirname, 'server.ts')
.expect({
event: {
exception: {
values: [
{

Fix in CursorFix in Web


@mydea mydea force-pushed the fn/vercel-ai-tests branch from 08659ea to 841cfef Compare July 24, 2025 08:02
@mydea mydea force-pushed the fn/vercel-ai-tests branch from 841cfef to 59e546e Compare July 24, 2025 08:57
@mydea mydea changed the title fix(vercel-ai): Ensure tool errors have correct trace connected fix(node): Ensure tool errors for vercelAiIntegration have correct trace connected Jul 24, 2025
@mydea mydea enabled auto-merge (squash) July 24, 2025 08:57
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Test Hangs Due to Zero Traces Sample Rate

The test removed .ignore('transaction') but the server is configured with tracesSampleRate: 0. Since tracesSampleRate: 0 prevents transaction events from being sent, the test runner will hang or timeout waiting for them. The test's purpose is to verify that error events still include transaction names even when transactions are not sampled, so it should continue to ignore transaction events.

dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts#L8-L14

test('should capture and send Express controller error with txn name if tracesSampleRate is 0', async () => {
const runner = createRunner(__dirname, 'server.ts')
.expect({
event: {
exception: {
values: [
{

Fix in CursorFix in Web


@mydea mydea merged commit c1991d6 into develop Jul 24, 2025
149 of 150 checks passed
@mydea mydea deleted the fn/vercel-ai-tests branch July 24, 2025 09:13
mydea added a commit that referenced this pull request Jul 24, 2025
…trace connected (#17132)

This fixes the problem that for tool errors triggered from vercel-ai
integration, traces were not connected.
This seemed to happen because errors bubble up to the global unhandled
rejection handler, where the span is no longer active and thus the trace
cannot be connected.

This PR fixes this by attaching the active span to the error and using
this in the unhandled rejection handler, if it exists.

Closes #17108
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.

Tool call errors have a different trace than tool call errors
3 participants