sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

NextJS Sentry is using deprecated `beforeNavigate` instead of `beforeStartSpan`

Open mpranjic24 opened this issue 1 year ago • 6 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.110.0

Framework Version

13.2.4

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: __YOUR_DSN__,
  tracesSampleRate: 0.1,
  environment: __YOUR_ENV__,
  integrations: [
    Sentry.browserTracingIntegration({
      beforeStartSpan: (context) => {
        console.log(context);
        return {
          ...context,
          name: getTransactionName(context),
        };
      },
    }),
  ],
});

Steps to Reproduce

Used configuration from above in sentry.client.config.ts by following the documentation.

Expected Result

Function beforeStartSpan should be called and a log should appear in console when it's called.

Actual Result

Function beforeStartSpan is never called. I suspect it's caused by the weird fixBrowserTracingIntegration method that converts the most recent browser tracing integration to the deprecated one.

What's more, using beforeNavigate actually works, but produces TypeScript errors since it's not defined in BrowserTracingOptions.

This is contrary to what the documentation says.

mpranjic24 avatar Apr 16 '24 13:04 mpranjic24

Hey, thanks for writing in! Hmm, this seems like a bug to me - we'll look into it!

mydea avatar Apr 17 '24 07:04 mydea

Fix released with https://github.com/getsentry/sentry-javascript/releases/tag/7.111.0 - please upgrade and give it a try!

AbhiPrasad avatar Apr 18 '24 16:04 AbhiPrasad

Unfortunately it doesn't seem to work, @AbhiPrasad. Nothing gets logged. On a side note, before the fix I could make it work with:

// @ts-expect-error: ignore TypeScript
      beforeNavigate(options: { name: string }) {
        ...
     }

That actually produced some console logs and in Chrome network view I could see that the transaction name got updated.

Now, it seems that it doesn't work at all.

mpranjic24 avatar Apr 19 '24 09:04 mpranjic24

I will look into it, it seems that something is really off there, sorry about that!

mydea avatar Apr 24 '24 07:04 mydea

So we've just released v7.112.2, where we hopefully actually have a full fix for your problem - sorry about the confusion! Gonna leave this open this time until I've got confirmation that the issue is actually solved 😅

mydea avatar Apr 24 '24 14:04 mydea

So we've just released v7.112.2, where we hopefully actually have a full fix for your problem - sorry about the confusion! Gonna leave this open this time until I've got confirmation that the issue is actually solved 😅

From what I can see, beforeStartSpan indeed gets called now 👍

Also, in the big "envelope/..." request I can see that the transaction property got changed in 2 places 👍

mpranjic24 avatar Apr 26 '24 12:04 mpranjic24

This seems to be fixed, so I am closing this 👍

s1gr1d avatar Apr 29 '24 08:04 s1gr1d