Skip to content

NextJS withServerActionInstrumentation marks redirect() server actions as internal_error transactions #21515

Description

@smozely

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

Have a NextJS Server action that does a redirect inside withServerActionInstrumentation

e.g. this server action

asyncfunctionserverAction(){awaitwithServerActionInstrumentation('serverAction',()=>{redirect('/foo');});}

Will be marked with a transaction in Sentry that had an "internal_error"

Runnable example (Claude generated, but human validated):

constSentry=require('@sentry/nextjs');constnav=require('next/navigation');consttransactions=[];Sentry.init({dsn: 'https://public@example.ingest.sentry.io/1',tracesSampleRate: 1,beforeSendTransaction(ev){transactions.push(ev);returnnull;},});asyncfunctionrun(name,body){try{awaitSentry.withServerActionInstrumentation(name,body);}catch{}}(async()=>{awaitrun('redirect',async()=>{nav.redirect('/login');});awaitrun('not-found',async()=>{nav.notFound();});awaitrun('success',async()=>'ok');awaitrun('genuine-error',async()=>{thrownewError('boom');});awaitSentry.flush(2000);for(consttoftransactions){console.log(t.transaction,'=>',t.contexts?.trace?.status);}})();
// Output:
// serverAction/redirect => internal_error <-- wrong
// serverAction/not-found => not_found
// serverAction/success => ok
// serverAction/genuine-error => internal_error

Expected Result

Should have not been marked as internal_error

Actual Result

Image

Product Area

Explore

Link

No response

DSN

https://b6d4dd5853e462b70bc0ca053c34e7dc@o4509326989918208.ingest.us.sentry.io/4509331771359232

Version

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions