getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.88k stars 1.55k forks source link

Nextjs `assetPrefix` not prepended to the uploaded assets, minified errors will be reported #8697

Closed PeterMK85 closed 1 year ago

PeterMK85 commented 1 year ago

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

7.58.1

Framework Version

13.2.3 (next)

Link to Sentry event

No response

SDK Setup

next.config.js

const nextConfig = {
    env: {
    },
    experimental: {
    },
    nx: {
        svgr: true,
    },
    assetPrefix,
    eslint: {
        ignoreDuringBuilds: true,
    },
    typescript: {
        ignoreBuildErrors: true,
    },
    trailingSlash: true,
    modularizeImports:
        process.env.NODE_ENV === 'production'
            ? undefined
            : {
              },
    async headers() {
        return [
            {
            },
        ]
    },
    async rewrites() {
        return {
        }
    },
    ...(serverEnv.SENTRY_ENABLED
        ? {
              sentry: {
                  // Use `hidden-source-map` rather than `source-map` as the Webpack `devtool`
                  // for client-side builds. (This will be the default starting in
                  // `@sentry/nextjs` version 8.0.0.) See
                  // https://webpack.js.org/configuration/devtool/ and
                  // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map
                  // for more information.
                  hideSourceMaps: true,

                  // This option will automatically provide performance monitoring for Next.js
                  // data-fetching methods and API routes, making the manual wrapping of API
                  // routes via `withSentry` redundant.
                  autoInstrumentServerFunctions: true,

                  widenClientFileUpload: true,

                  disableLogger: true,
              },
          }
        : {}),
}

const sentryWebpackPluginOptions = {
    // Additional config options for the Sentry Webpack plugin. Keep in mind that
    // the following options are set automatically, and overriding them is not
    // recommended:
    //   release, url, org, project, authToken, configFile, stripPrefix,
    //   urlPrefix, include, ignore
    silent: !serverEnv.DEBUG, // Suppresses all logs
    // For all available options, see:
    // https://github.com/getsentry/sentry-webpack-plugin#options.
    setCommits: {
        auto: true,
    },
    debug: serverEnv.DEBUG,
    ignore: [],
}

sentry.client.config.js

Sentry.init({
    dsn: clientEnv.NEXT_PUBLIC_SENTRY_CLIENT_DSN,
    // Adjust this value in production, or use tracesSampler for greater control
    tracesSampleRate: clientEnv.NEXT_PUBLIC_SENTRY_CLIENT_TRACES_SAMPLE_RATE,
    initialScope: {
        tags: {
        },
    },
    // ...
    // Note: if you want to override the automatic release value, do not set a
    // `release` value here - use the environment variable `SENTRY_RELEASE`, so
    // that it will also get attached to your source maps
    // Retain deeply nested objects in ADDITIONAL DATA section
    normalizeDepth: 10,
    integrations: [
        new RewriteFrames({
            iteratee: (mutableFrame) => {
                if (mutableFrame.filename) {
                    mutableFrame.filename = decodeURI(mutableFrame.filename)
                }

                return mutableFrame
            },
        }),
        new Sentry.BrowserTracing({
            tracePropagationTargets: [/^\/api\//],
            beforeNavigate: (context) => ({
                ...context,
                // eslint-disable-next-line no-restricted-globals
                name: getPathWithVariables(location.pathname),
            }),
        }),
    ],
    ignoreErrors: [
        // Chrome-specific error thrown by Grammarly
        // harmless, can be safely ignored https://stackoverflow.com/a/50387233/339176
        'ResizeObserver loop limit exceeded',
        // harmless, specification says it could be ignored https://github.com/juggle/resize-observer/issues/103#issuecomment-610223544
        'ResizeObserver loop completed with undelivered notifications',
        // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html
        'originalCreateNotification',
        // Random plugins/extensions
        'top.GLOBALS',
        // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html
        'originalCreateNotification',
        'canvas.contentDocument',
        'MyApp_RemoveAllHighlights',
        'http://tt.epicplay.com',
        "Can't find variable: ZiteReader",
        'jigsaw is not defined',
        'ComboSearch is not defined',
        'http://loading.retry.widdit.com/',
        'atomicFindClose',
        // Facebook borked
        'fb_xd_fragment',
        // ISP "optimizing" proxy - `Cache-Control: no-transform` seems to reduce this. (thanks @acdha)
        // See http://stackoverflow.com/questions/4113268/how-to-stop-javascript-injection-from-vodafone-proxy
        'bmi_SafeAddOnload',
        'EBCallBackMessageReceived',
        // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
        'conduitPage',
        // Avast extension error
        '_avast_submit',
    ],
    denyUrls: [
        // Chrome extensions
        /extensions\//i,
        /chrome-extension/i,
        /^chrome:\/\//i,
        /safari-extension/,
        // Google Adsense
        /pagead\/js/i,
        // Facebook flakiness
        /graph\.facebook\.com/i,
        // Facebook blocked
        /connect\.facebook\.net\/en_us\/all\.js/i,
        // Woopra flakiness
        /eatdifferent\.com\.woopra-ns\.com/i,
        /static\.woopra\.com\/js\/woopra\.js/i,
        // Chrome extensions
        /extensions\//i,
        /^chrome:\/\//i,
        // Other plugins
        /127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
        /webappstoolbarba\.texthelp\.com\//i,
        /metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
    ],
})

sentry.server.config.js

Sentry.init({
    dsn: 
    // Adjust this value in production, or use tracesSampler for greater control
    tracesSampleRate: 
    environment: 
    initialScope: {
        tags: {
        },
    },
    debug: serverEnv.DEBUG,
    // ...
    // Note: if you want to override the automatic release value, do not set a
    // `release` value here - use the environment variable `SENTRY_RELEASE`, so
    // that it will also get attached to your source maps
    // Retain deeply nested objects in ADDITIONAL DATA section
    normalizeDepth: 10,
})

Steps to Reproduce

The issue that is basically ~/_next/server/pages/401.js won't match on errors with the https://cdn.*.com/frontdoor/_next/server/pages/401.js

During build the following output printed:

11:00:48  #15 28.03  ENV ASSET_PREFIX is https://cdn.*.com/frontdoor
...
11:02:11  #15 100.6 Source Map Upload Report
11:02:11  #15 100.6   Scripts
11:02:11  #15 100.6     ~/_next/server/pages/401.js
11:02:11  #15 100.6     ~/_next/server/pages/403.js
11:02:11  #15 100.6     ~/_next/server/pages/404.js
...
11:02:11  #15 100.6   Source Maps
11:02:11  #15 100.6     ~/_next/server/pages/401.js.map
11:02:11  #15 100.6     ~/_next/server/pages/403.js.map
11:02:11  #15 100.6     ~/_next/server/pages/404.js.map
11:02:11  #15 100.6     ~/_next/server/pages/410.js.map

Expected Result

The assetpath is being respected during the sourcemap upload.

Actual Result

The assetpath is being ignored during the sourcemap upload.

lforst commented 1 year ago

Hi, thanks for writing in! Can you share a stacktrace where this is a problem? Thanks!

lforst commented 1 year ago

Also, can you try removing the RewriteFrames integration from your integrations array? Thanks!

PeterMK85 commented 1 year ago

Also, can you try removing the RewriteFrames integration from your integrations array? Thanks!

After removing the RewriteFrames the error properly matched with the CDN assets. (also updated to the latest 7.61.1)

Thanks 🙇

lforst commented 1 year ago

Also, can you try removing the RewriteFrames integration from your integrations array? Thanks!

After removing the RewriteFrames the error properly matched with the CDN assets. (also updated to the latest 7.61.1)

Thanks 🙇

Amazing! Thank you for following up :)