Skip to content

[NextJS] No data being sent from server-side functions #17193

Closed

Description

@cbovis

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

9.42.1

Framework Version

NextJS 15.4.4

Link to Sentry event

No response

Reproduction Example/SDK Setup

I've set up a repo with an app that reproduces the problem consistently: https://github.com/cbovis/nextjs-sentry-server-bug. The repo just contains a template NextJS app with most of the set up instructions from https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ applied to it.

An API route exists which calls logger.info and then throws an error. On the app's homepage there's a "break the world" button which calls that endpoint as per the verify step of the setup guide (https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#step-8-verify). The homepage also calls logger.info.

It's configured with a real DSN which hopefully the Sentry team can view the associated data of.

The reproduction is only broken when deployed to Vercel (standard configuration). When running locally data gets sent to Sentry as expected from both client and server code.

When running locally with debug enabled I see that Sentry flushes data a little while after the API request completes. I'm wondering if this issue is only see in Vercel because of the serverless environment being destroyed before flushing happens. NextJS has an after function for scheduling work after a request is finished (https://nextjs.org/docs/app/api-reference/functions/after). Perhaps this isn't being used?

Steps to Reproduce

Hosted at https://nextjs-sentry-server-bug.vercel.app/ for convenience.

  1. Hit the homepage of the app and click the button.
  2. Access the API route manually for good measure (https://nextjs-sentry-server-bug.vercel.app/api/sentry-example-api)

Expected Result

Expect to see logging and errors in the associated Sentry account for production environment. Also expect to see both frontend/backend transactions and spans.

Actual Result

Only logging, errors, transactions, and spans are stored for client-side code, not server-side code.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 28, 2025
  2. cbovis commented on Jul 28, 2025

    @cbovis
    Author

    May be related to #17136

  3. self-assigned this
    on Jul 29, 2025
  4. chargome commented on Jul 29, 2025

    @chargome
    Member

    Hey @cbovis thanks for providing a repro with that, I'll take a look

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 29, 2025
  6. chargome commented on Jul 29, 2025

    @chargome
    Member

    Ok looks like the lambda is completely freezing and sometimes cuts off the envelope to be sent. In a production app that has some traffic on it this should not have a big effect, but we need to nevertheless fix this. I'll see if we can make use of the after util here, thanks for the hint!

  7. chargome commented on Jul 30, 2025

    @chargome
    Member

    @cbovis thanks again for raising this. The linked PR fixed this issue in my testapp – in case anyone is still running into this issue (especially since the fix will not yet work for turbopack prod builds) please make use of:

    import { after } from 'next/server';
    import * as Sentry from '@sentry/nextjs';
    
    export function GET() {
        after(() => {
            Sentry.flush();
        });
        // rest of your handler
    }
  8. github-actions commented on Jul 31, 2025

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #17223, which was included in the 10.0.0 release.

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