Skip to content
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

Error serializing ._sentryBaggage returned from getServerSideProps #12102

Closed
3 tasks done
dorin-flooz opened this issue May 17, 2024 · 8 comments · Fixed by #12131
Closed
3 tasks done

Error serializing ._sentryBaggage returned from getServerSideProps #12102

dorin-flooz opened this issue May 17, 2024 · 8 comments · Fixed by #12131

Comments

@dorin-flooz
Copy link

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

8.2.1

Framework Version

NextJs 14.2.3

Link to Sentry event

No response

SDK Setup

import * as Sentry from '@sentry/nextjs';
import { appVersionUtils } from './src/modules/application/utils/app-version-utils';

const SENTRY_DSN = process.env.SENTRY_DSN ?? process.env.NEXT_PUBLIC_SENTRY_DSN;
const APP_VERSION = appVersionUtils.getAppVersion();

const commonSentryOptions = {
    release: APP_VERSION,
    environment: process.env.NEXT_PUBLIC_ENV,
    dsn: SENTRY_DSN,
    enabled: false, // process.env.NODE_ENV !== 'development',
    tracesSampleRate: 1,
};

export async function register() {
    if (process.env.NEXT_RUNTIME === 'nodejs') {
        Sentry.init({
            ...commonSentryOptions,
        });
    }

    if (process.env.NEXT_RUNTIME === 'edge') {
        Sentry.init({
            ...commonSentryOptions,
        });
    }
}

Steps to Reproduce

After upgrading to "@sentry/nextjs": "8.2.1", we get the following error:

Error: Error serializing `._sentryBaggage` returned from `getServerSideProps` in "/profile/[ensOrAddress]".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

When reverting to "@sentry/nextjs": "7.115.0" the error goes away. How can we debug and fix this? Searched for sentryBaggage already, but nothing came up.

Also - how come we get Sentry errors in our local dev env, when Sentry is explicitly disabled through enabled: false in our Sentr.init?

Expected Result

  • Sentry should not be enabled in local env
  • Sentry should not prevent NextJs pages from loading in case getServerSideProps fails

Actual Result

  • Sentry is enabled in local env
  • Sentry prevents NextJs pages from loading in case getServerSideProps fails
@samsch
Copy link

samsch commented May 17, 2024

I came to report the same error. Additional context:

Also happens with 8.0.0 and 8.1.0.

Specifically only happening with getServerSideProps, other pages using getStaticProps work fine. My getServerSideProps implementations are not directly interacting with Sentry code.

@jeniabrook
Copy link

I have the same behavior as @samsch and @dorin-flooz.

@Nastoc4ka
Copy link

I am using next js pages.
So I moved instrumentation file from root to src, and error disappeared. If that was a problem for you.

@mengqing
Copy link

I am using next js pages. So I moved instrumentation file from root to src, and error disappeared. If that was a problem for you.

Hi @Nastoc4ka, which instrumentation file are you referring to specifically?

@Nastoc4ka
Copy link

when you move from 7 to 8, you are creating instrumentation file and removing sentry.server.config.js according to documentation. Did you follow migration guide: https://docs.sentry.io/platforms/javascript/guides/nextjs/migration/v7-to-v8/

@EfstathiadisD
Copy link

EfstathiadisD commented May 20, 2024

I have the same issue. I don't have a src directory. I followed the instructions and nothing. Why is it becoming so complicating to wrap our Apps with Sentry, and why does it run on development?

UPDATE:
I found the issue. The issue is that Sentry needs to init no matter what. That is a bit controversial. It means that if Sentry is down my app is down. Am I understanding this correctly?

The moment I amde sentry available to be init every time it started working. If I check for production env, or DSN availability it doesn't. Why?

@mitsuhiko
Copy link
Member

I found the issue. The issue is that Sentry needs to init no matter what. That is a bit controversial. It means that if Sentry is down my app is down. Am I understanding this correctly?

Sentry protects against sentry being down. Yes you need to initialize Sentry all the time, but for instance if you pass an empty DSN it disables most of all functionality (eg: sending any error at all).

@lforst
Copy link
Member

lforst commented May 21, 2024

Hi, from looking at it it seems that Next.js uses a custom serializer that cannot handle undefined. You should always be safe to omit calling Sentry.init() no matter what. We will fix setting _sentryBaggage to undefined in the props.

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

Successfully merging a pull request may close this issue.

8 participants