getsentry / sentry-javascript

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

Sentry CLI not running on Vercel (NextJS 12) but running fine locally #6675

Closed georgiosd closed 1 year ago

georgiosd commented 1 year ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.29.0

Framework Version

React 17.0.2, Next 12.3.4

Link to Sentry event

No response

Steps to Reproduce

I have set all SENTRY_* env vars on Vercel, and I even tried copying them locally and running the build. It creates the release and upload the source maps to Sentry just fine. When I push code and the build runs on Vercel, nothing.

I read through all the issues I could find, but didn't find anything that worked or seemed relevant. The build succeeds without any issues.

My next.config.js:

const { withSentryConfig } = require('@sentry/nextjs')
const withTM = require('next-transpile-modules')([
  ...
])
const { i18n } = require('./next-i18next.config')

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  compiler: {
    styledComponents: true,
  },
  experimental: {
    modularizeImports: {
      'react-bootstrap': {
        transform: 'react-bootstrap/{{member}}',
      },
    },
  },
  i18n,
  sentry: {
    hideSourceMaps: true,
  },
}

const sentryWebpackPluginOptions = {
}

module.exports = withSentryConfig(
  withTM(nextConfig),
  sentryWebpackPluginOptions
)

Typical Vercel build log (reduced):

➤ YN0000: │ @sentry/cli@npm:1.74.6 STDOUT fetching sentry-cli-Linux-x86_64 95%
--
19:30:20.557 | ➤ YN0000: │ @sentry/cli@npm:1.74.6 STDOUT fetching sentry-cli-Linux-x86_64 100%
19:30:20.583 | ➤ YN0000: │ @sentry/cli@npm:1.74.6 STDERR info Checksum validation passed.
19:30:20.667 | ➤ YN0007: │ @xxx/root@workspace:. must be built because it never has been before or the last one failed
19:30:22.358 | ➤ YN0000: │ @xxx/root@workspace:. STDOUT ☔️ success workspaces valid!
19:30:22.374 | ➤ YN0000: └ Completed in 6s 71ms
19:30:22.588 | ➤ YN0000: Done with warnings in 1m 17s
19:30:22.769 | Detected Next.js version: 12.3.4
19:30:22.770 | Running "yarn build"
19:30:24.094 | warn  - You have enabled experimental feature (modularizeImports) in next.config.js.
19:30:24.095 | warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
19:30:24.095 |  
19:30:24.199 | info  - Linting and checking validity of types...
19:30:41.770 | info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
19:30:44.667 | info  - Creating an optimized production build...
19:31:06.761 | info  - Compiled successfully
19:31:06.761 | info  - Collecting page data...
19:31:10.448 | info  - Generating static pages (0/14)
19:31:10.503 | info  - Generating static pages (3/14)
19:31:10.514 | info  - Generating static pages (6/14)
19:31:10.525 | info  - Generating static pages (10/14)
19:31:10.554 | info  - Generating static pages (14/14)
19:31:10.574 | info  - Finalizing page optimization...
19:31:10.581 |  ...
19:31:11.648 | Traced Next.js server files in: 593.844ms
19:31:13.410 | Created all serverless functions in: 1.761s
19:31:13.422 | Collected static files (public/, static/, .next/static): 8.804ms
19:31:14.492 | Build Completed in /vercel/output [2m]
19:31:19.208 | Generated build outputs:
19:31:19.210 | - Static files: 80
19:31:19.210 | - Serverless Functions: 11
19:31:19.210 | - Edge Functions: 0
19:31:19.211 | Serverless regions: Washington, D.C., USA
19:31:19.211 | Deployed outputs in 3s
19:31:20.063 | Build completed. Populating build cache...
19:31:34.065 | Uploading build cache [86.35 MB]...
19:31:36.663 | Build cache uploaded: 2.598s

Expected Result

Creates release and uploads source map.

Actual Result

No release (this used to happen before I upgraded Sentry) and no source maps uploaded, as per Source Maps view in Sentry.

lforst commented 1 year ago

Source maps are only uploaded on Vercel if the deployment target is production. Source maps will not be uploaded for preview or development environments. Could this be the case for you?

georgiosd commented 1 year ago

It is, but thats unintended behavior- we use preview environments for acceptance testing and sentries really need meaningful stack traces to be useful.

Is there a way to customize that?

On Sat, 7 Jan 2023 at 13:42, Luca Forstner @.***> wrote:

Source maps are only uploaded on Vercel if the deployment target is production. Source maps will not be uploaded for preview or development environments. Could this be the case for you?

— Reply to this email directly, view it on GitHub https://github.com/getsentry/sentry-javascript/issues/6675#issuecomment-1374452101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMYG5X42YAIW76CCGTU2F3WRFJCRANCNFSM6AAAAAATTJVZAY . You are receiving this because you authored the thread.Message ID: @.***>

lforst commented 1 year ago

As of now, there is a hacky way to do it. You could manually set disableServerWebpackPlugin and disableServerWebpackPlugin to false, depending on whether you want source maps uploaded or not.

I agree though that this UX is kinda crappy though and we should think of something better here.

georgiosd commented 1 year ago

@lforst Thank you. This is new right? I'd say at the very least add to docs and/or samples...

lforst commented 1 year ago

@georgiosd These options? No they've been around for a while and are also part of the docs.

georgiosd commented 1 year ago

I would swear this wasn't a problem before - we have several NextJS apps (this particular one is new). Maybe we're running on old SDKs?

Re docs, I meant it would be good to connect these two options with some sort of environment check...

lforst commented 1 year ago

PRs are always welcome!

georgiosd commented 1 year ago

Definitely open to that - can you please point me in the right direction on where I'd suggest that edit?

lforst commented 1 year ago

https://github.com/getsentry/sentry-docs is the place!

github-actions[bot] commented 1 year ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

georgiosd commented 1 year ago

@lforst just revisiting this - I guess the change should go to https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/?original_referrer=https%3A%2F%2Fduckduckgo.com%2F#configure-source-maps ?

Can you confirm the defaults are these?

disableServerWebpackPlugin: true,
disableClientWebpackPlugin: true,

Or is there some other logic?

EDIT

I did find the logic related to this and it seems that both plugins are activated by default: https://github.com/getsentry/sentry-javascript/blob/5543808adf70280b0154a4e7c1d446f2b171c07d/packages/nextjs/src/config/webpack.ts#L813

But then it doesn't make sense I am having this problem.

What am I missing here?

lforst commented 1 year ago

If you update everything to the newest version and provide all the necessary environment variables you should get source mapped events on preview environments now.

georgiosd commented 1 year ago

Ok, thank you!

On Mon, 22 May 2023 at 17:57, Luca Forstner @.***> wrote:

If you update everything to the newest version and provide all the necessary environment variables you should get source mapped events on preview environments now.

— Reply to this email directly, view it on GitHub https://github.com/getsentry/sentry-javascript/issues/6675#issuecomment-1557372325, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMYG5Q76DLPFBMF4W6FP23XHN5GXANCNFSM6AAAAAATTJVZAY . You are receiving this because you were mentioned.Message ID: @.***>