Skip to content

Conversation

@chargome
Copy link
Member

@chargome chargome commented Dec 4, 2025

@chargome chargome self-assigned this Dec 4, 2025
@linear
Copy link

linear bot commented Dec 4, 2025

@chargome chargome requested a review from logaretm December 5, 2025 09:50
@chargome chargome marked this pull request as ready for review December 5, 2025 09:50
Comment on lines 40 to 45
() => originalFunction.apply(thisArg, args),
error => {
const isolationScope = getIsolationScope();
const span = getActiveSpan();
const { componentRoute, componentType } = context;
isolationScope.setTransactionName(`${componentType} Server Component (${componentRoute})`);

This comment was marked as outdated.

Comment on lines 58 to 68

return startSpanManual(
{
op: 'function.nextjs',
name: `${componentType} Server Component (${componentRoute})`,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.server_component',
'sentry.nextjs.ssr.function.type': componentType,
'sentry.nextjs.ssr.function.route': componentRoute,
},
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
span => {
return handleCallbackErrors(
() => originalFunction.apply(thisArg, args),
error => {
// When you read this code you might think: "Wait a minute, shouldn't we set the status on the root span too?"
// The answer is: "No." - The status of the root span is determined by whatever status code Next.js decides to put on the response.
if (isNotFoundNavigationError(error)) {
// We don't want to report "not-found"s
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'not_found' });
} else if (isRedirectNavigationError(error)) {
// We don't want to report redirects
span.setStatus({ code: SPAN_STATUS_OK });
} else {
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
});
}
},
() => {
span.end();
waitUntil(flushSafelyWithTimeout());
},
);
},
);
});
});
});
},
() => {
waitUntil(flushSafelyWithTimeout());
},

This comment was marked as outdated.

() => {
waitUntil(flushSafelyWithTimeout());
},
);
Copy link

Choose a reason for hiding this comment

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

Bug: Missing isolation scope context breaks request metadata attachment

The refactored code retrieves an isolation scope via commonObjectToIsolationScope at line 29 and sets normalizedRequest metadata on it, but the handleCallbackErrors callback is not wrapped with withIsolationScope. When captureException is called in the error handler, getIsolationScope() at line 42 returns the current global isolation scope - not the one with the request metadata. This causes captured exceptions to be missing request context (like headers) that was set up earlier. The original code used withIsolationScope(isolationScope, ...) to ensure all nested code ran with the correct isolation scope.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

the scope already gets forked earlier

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,120 - 9,024 +1%
GET With Sentry 1,628 18% 1,691 -4%
GET With Sentry (error only) 5,959 65% 6,133 -3%
POST Baseline 1,181 - 1,201 -2%
POST With Sentry 569 48% 582 -2%
POST With Sentry (error only) 1,046 89% 1,051 -0%
MYSQL Baseline 3,258 - 3,304 -1%
MYSQL With Sentry 394 12% 460 -14%
MYSQL With Sentry (error only) 2,649 81% 2,684 -1%

View base workflow run

Comment on lines +53 to +63
} else if (isRedirectNavigationError(error)) {
shouldCapture = false;
// We don't want to report redirects
span.setStatus({ code: SPAN_STATUS_OK });
} else {
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
}
}

return startSpanManual(
{
op: 'function.nextjs',
name: `${componentType} Server Component (${componentRoute})`,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.server_component',
'sentry.nextjs.ssr.function.type': componentType,
'sentry.nextjs.ssr.function.route': componentRoute,
if (shouldCapture) {
captureException(error, {

This comment was marked as outdated.

Comment on lines +64 to +74
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
},
span => {
return handleCallbackErrors(
() => originalFunction.apply(thisArg, args),
error => {
// When you read this code you might think: "Wait a minute, shouldn't we set the status on the root span too?"
// The answer is: "No." - The status of the root span is determined by whatever status code Next.js decides to put on the response.
if (isNotFoundNavigationError(error)) {
// We don't want to report "not-found"s
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'not_found' });
} else if (isRedirectNavigationError(error)) {
// We don't want to report redirects
span.setStatus({ code: SPAN_STATUS_OK });
} else {
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
});
}
},
() => {
span.end();
waitUntil(flushSafelyWithTimeout());
},
);
},
);
});
});
});
}
},
() => {
waitUntil(flushSafelyWithTimeout());
},
);

This comment was marked as outdated.

});
});
});
}
Copy link

Choose a reason for hiding this comment

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

Bug: Exceptions never captured due to unset shouldCapture flag

The shouldCapture variable is initialized to false on line 45 and never set to true. In the original code, captureException was called directly in the else branch for actual errors. Now it's guarded by if (shouldCapture), but the else branch (lines 57-58) only sets the span status without setting shouldCapture = true. This means real exceptions from server components will never be captured by Sentry.

Fix in Cursor Fix in Web

page,
}) => {
const serverTransactionEventPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
console.log(transactionEvent?.transaction);
Copy link

Choose a reason for hiding this comment

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

Bug: Debug console.log left in test code

A console.log(transactionEvent?.transaction) statement appears to have been left in the test code, likely from debugging. While this is in test code, it will produce unnecessary output during test runs.

Fix in Cursor Fix in Web

Comment on lines +64 to +74
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
},
span => {
return handleCallbackErrors(
() => originalFunction.apply(thisArg, args),
error => {
// When you read this code you might think: "Wait a minute, shouldn't we set the status on the root span too?"
// The answer is: "No." - The status of the root span is determined by whatever status code Next.js decides to put on the response.
if (isNotFoundNavigationError(error)) {
// We don't want to report "not-found"s
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'not_found' });
} else if (isRedirectNavigationError(error)) {
// We don't want to report redirects
span.setStatus({ code: SPAN_STATUS_OK });
} else {
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
});
}
},
() => {
span.end();
waitUntil(flushSafelyWithTimeout());
},
);
},
);
});
});
});
}
},
() => {
waitUntil(flushSafelyWithTimeout());
},
);
Copy link

Choose a reason for hiding this comment

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

Bug: The transaction name for successful server component requests is not being set because setTransactionName() is only called within the error handler.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

In wrapServerComponentWithSentry, transaction names for successful server component requests are no longer being set. The call to scope.setTransactionName() was moved into the error handler of handleCallbackErrors. Consequently, for any server component that executes without throwing an error, the transaction name will not be set, which is a functional regression from the previous implementation where it was set for both success and error paths. This affects transaction identification in Sentry for all successful server component renders.

💡 Suggested Fix

Move the setTransactionName() call out of the error handler and into a withScope or withIsolationScope block that wraps the component's execution, similar to the previous implementation. This will ensure the transaction name is set for both successful and failed executions.

🤖 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/nextjs/src/common/wrapServerComponentWithSentry.ts#L39-L74

Potential issue: In `wrapServerComponentWithSentry`, transaction names for successful
server component requests are no longer being set. The call to
`scope.setTransactionName()` was moved into the error handler of `handleCallbackErrors`.
Consequently, for any server component that executes without throwing an error, the
transaction name will not be set, which is a functional regression from the previous
implementation where it was set for both success and error paths. This affects
transaction identification in Sentry for all successful server component renders.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7443279

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 is just relevant for the error case

Comment on lines 67 to 77
},
},
span => {
return handleCallbackErrors(
() => originalFunction.apply(thisArg, args),
error => {
// When you read this code you might think: "Wait a minute, shouldn't we set the status on the root span too?"
// The answer is: "No." - The status of the root span is determined by whatever status code Next.js decides to put on the response.
if (isNotFoundNavigationError(error)) {
// We don't want to report "not-found"s
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'not_found' });
} else if (isRedirectNavigationError(error)) {
// We don't want to report redirects
span.setStatus({ code: SPAN_STATUS_OK });
} else {
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
captureException(error, {
mechanism: {
handled: false,
type: 'auto.function.nextjs.server_component',
},
});
}
},
() => {
span.end();
waitUntil(flushSafelyWithTimeout());
},
);
},
);
});
});
});
}
},
() => {
waitUntil(flushSafelyWithTimeout());
},
);
},
});
}
Copy link

Choose a reason for hiding this comment

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

Bug: The sentry-trace header is no longer being extracted and set as the TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL attribute, which breaks distributed tracing for server components.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL attribute is no longer being set on the root span for server components. The refactored wrapServerComponentWithSentry function omits the logic that extracts the sentry-trace header and sets it as an attribute on the span. Downstream event processors rely on this attribute to correctly backfill trace context and make sampling decisions. Its absence breaks distributed tracing for server components, as the trace context from incoming requests will not be propagated.

💡 Suggested Fix

Reintroduce the logic to read the sentry-trace header from the request and set it as the TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL attribute on the root span. This logic could be added back to wrapServerComponentWithSentry or into the new handleOnSpanStart function to align with wrapGenerationFunctionWithSentry.

🤖 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/nextjs/src/common/wrapServerComponentWithSentry.ts#L36-L77

Potential issue: The `TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL` attribute is no longer
being set on the root span for server components. The refactored
`wrapServerComponentWithSentry` function omits the logic that extracts the
`sentry-trace` header and sets it as an attribute on the span. Downstream event
processors rely on this attribute to correctly backfill trace context and make sampling
decisions. Its absence breaks distributed tracing for server components, as the trace
context from incoming requests will not be propagated.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7443279

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.81 kB - -
@sentry/browser - with treeshaking flags 23.3 kB - -
@sentry/browser (incl. Tracing) 41.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.14 kB - -
@sentry/browser (incl. Tracing, Replay) 79.97 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.7 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.89 kB - -
@sentry/browser (incl. Feedback) 41.52 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB - -
@sentry/browser (incl. FeedbackAsync) 34.48 kB - -
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.75 kB - -
@sentry/vue 29.27 kB - -
@sentry/vue (incl. Tracing) 43.36 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.24 kB - -
CDN Bundle (incl. Tracing) 42.23 kB - -
CDN Bundle (incl. Tracing, Replay) 78.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 84.21 kB - -
CDN Bundle - uncompressed 80.04 kB - -
CDN Bundle (incl. Tracing) - uncompressed 125.39 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.18 kB - -
@sentry/nextjs (client) 45.97 kB - -
@sentry/sveltekit (client) 41.92 kB - -
@sentry/node-core 51.5 kB - -
@sentry/node 159.94 kB - -
@sentry/node - without tracing 92.91 kB +0.02% +14 B 🔺
@sentry/aws-serverless 108.44 kB - -

View base workflow run

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.

Remove tracing from App Router Server Components templates

2 participants