Skip to content

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

@smozely

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

async function serverAction() {
  await withServerActionInstrumentation('serverAction', () => {
    redirect('/foo');
  });
}

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

Runnable example (Claude generated, but human validated):

const Sentry = require('@sentry/nextjs');
const nav = require('next/navigation');

const transactions = [];
Sentry.init({
  dsn: 'https://public@example.ingest.sentry.io/1',
  tracesSampleRate: 1,
  beforeSendTransaction(ev) {
    transactions.push(ev);
    return null;
  },
});

async function run(name, body) {
  try {
    await Sentry.withServerActionInstrumentation(name, body);
  } catch {}
}

(async () => {
  await run('redirect', async () => {
    nav.redirect('/login');
  });
  await run('not-found', async () => {
    nav.notFound();
  });
  await run('success', async () => 'ok');
  await run('genuine-error', async () => {
    throw new Error('boom');
  });
  await Sentry.flush(2000);
  for (const t of transactions) {
    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

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions