getsentry / sentry-javascript

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

while deploying my nextjs project with sentry on aws amplify build getting failed #8790

Closed gauravsapkal1 closed 1 year ago

gauravsapkal1 commented 1 year ago

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

7.61.0

Framework Version

nextjs 11.1.3

Link to Sentry event

https://...-ai-3o.sentry.io/settings/projects/...-error-tracking/source-maps/release-bundles/WJ_X-JoRolWj-H7LEOrk7/

SDK Setup

next.config.js File

const { withSentryConfig } = require("@sentry/nextjs");
const nextConfig = {
  ...nextConfigurations
  productionBrowserSourceMaps: true,
  sentry:{
    widenClientFileUpload: true,
    transpileClientSDK: true,
    hideSourceMaps: true,
    disableLogger: true,
  }
};

const sentryWebpackPluginOptions = {
  org: process.env.NEXT_PUBLIC_SENTRY_ORG_NAME,
  project: process.env.NEXT_PUBLIC_SENTRY_PROJECT_NAME,
  authToken: process.env.NEXT_PUBLIC_SENTRY_AUTH_TOKEN,
  sourceMapFilename: '[name].[hash].js.map',
  silent: true,
};

module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);

sentry.client.config.js


import * as Sentry from "@sentry/nextjs";
import { ContextLines } from "@sentry/integrations";

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  tracesSampleRate: 0.2,
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 0.1,
  integrations: [
    new Sentry.Replay(),
    new ContextLines({
      frameContextLines: 7,
    }),
  ],
});

app.js

 Sentry.init({
        dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
        integrations: [
          new BrowserTracing()
        ],
        tracesSampleRate: 0.2,
      });

So this setup works well for me in locally when i build locally sourcemap getting uploaded to my sentry dashboard and also i get proper stack starce but when i try to deploy on aws amplify my build is failing and getting below error

'> Build error occurred\n' +
                                  'Error: spawn ENOMEM\n' +
                                  '    at ChildProcess.spawn (node:internal/child_process:420:11)\n' +
                                  '    at spawn (node:child_process:733:9)\n' +
                                  '    at fork (node:child_process:169:10)\n' +
                                  '    at ChildProcessWorker.initialize (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/workers/ChildProcessWorker.js:141:45)\n' +
                                  '    at new ChildProcessWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/workers/ChildProcessWorker.js:132:10)\n' +
                                  '    at WorkerPool.createWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/WorkerPool.js:44:12)\n' +
                                  '    at new BaseWorkerPool (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/base/BaseWorkerPool.js:135:27)\n' +
                                  '    at new WorkerPool (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/WorkerPool.js:30:1)\n' +
                                  '    at new Worker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/index.js:167:26)\n' +
                                  '    at createWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/lib/worker.js:15:28)\n' +
                                  '    at new Worker1 (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/lib/worker.js:21:9)\n' +
                                  '    at /codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/build/index.js:432:31\n' +
                                  '    at async Span.traceAsyncFn (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/telemetry/trace/trace.js:60:20)\n' +
                                  '    at async Object.build [as default] (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/build/index.js:77:25) {\n' +
                                  '  errno: -12,\n' +
                                  "  code: 'ENOMEM',\n" +
                                  "  syscall: 'spawn'\n" +
                                  '}',
                                  failed: true,
                                  timedOut: false,
                                  isCanceled: false,
                                  killed: false
                                  }
                                  [G
2023-08-10T16:47:33.927Z [ERROR]: [?25h[G[J
                                  300s › darxjey0xrl5c › Error: Command failed with exit code 1: node_modules/.bin/next build

I am not getting why I am getting this problem only when i deploy it on aws amplify locally everything working fine.

Steps to Reproduce

after deploying my nextjs sentry project on aws amplify build getting failed.

Expected Result

Buil should not fail and my application should run smoothly and track errors properly

Actual Result

'> Build error occurred\n' + 'Error: spawn ENOMEM\n' + ' at ChildProcess.spawn (node:internal/child_process:420:11)\n' + ' at spawn (node:child_process:733:9)\n' + ' at fork (node:child_process:169:10)\n' + ' at ChildProcessWorker.initialize (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/workers/ChildProcessWorker.js:141:45)\n' + ' at new ChildProcessWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/workers/ChildProcessWorker.js:132:10)\n' + ' at WorkerPool.createWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/WorkerPool.js:44:12)\n' + ' at new BaseWorkerPool (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/base/BaseWorkerPool.js:135:27)\n' + ' at new WorkerPool (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/WorkerPool.js:30:1)\n' + ' at new Worker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/node_modules/jest-worker/build/index.js:167:26)\n' + ' at createWorker (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/lib/worker.js:15:28)\n' + ' at new Worker1 (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/lib/worker.js:21:9)\n' + ' at /codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/build/index.js:432:31\n' + ' at async Span.traceAsyncFn (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/telemetry/trace/trace.js:60:20)\n' + ' at async Object.build [as default] (/codebuild/output/src489982623/src/...-nextjs/node_modules/next/dist/build/index.js:77:25) {\n' + ' errno: -12,\n' + " code: 'ENOMEM',\n" + " syscall: 'spawn'\n" + '}', failed: true, timedOut: false, isCanceled: false, killed: false } [G 2023-08-10T16:47:33.927Z [ERROR]: [?25h[G[J 300s › darxjey0xrl5c › Error: Command failed with exit code 1: node_modules/.bin/next build

AbhiPrasad commented 1 year ago

@gauravsapkal1 does this error occur if you remove withSentryConfig? Might also be worthwhile reaching out to folks at https://github.com/aws-amplify/amplify-hosting

gauravsapkal1 commented 1 year ago

@AbhiPrasad yes deployment works fine after removing sentry

gauravsapkal1 commented 1 year ago

@AbhiPrasad is this issue due to more processing at time of build to create sourcemaps ?

lforst commented 1 year ago

@gauravsapkal1 we don't know. It might very well be that your app already needed a lot of memory during build and adding Sentry just tipped it over the edge. We would need some kind profile to know if there is an issue, and if so, what it is.

javierguzman commented 1 year ago

Came here looking for similar issues and I believe this might be related. I am building ok my Nextjs app locally on my MacOS, however, when I try to run "npm run build" within a Dockerfile fails with:

Sentry CLI Plugin: spawn Unknown system error -8

Do you think this could be related or should I open a new issue @lforst ?

Thank you in advance

lforst commented 1 year ago

@javierguzman I don't think this is related. Please open a new issue with some instructions on what one needs to do in order to run into your problem! Thanks!

gauravsapkal1 commented 1 year ago

@lforst yes might be adding Sentry just tipped my memory usage on amplify, and this happend due to generation and upload process of sourcemaps. So I am thinking to not generate source-maps on amplify while building nextjs app, instead to generate and upload source-maps through github actions workflow. So is it possible to generate and upload sourcemaps on github actions workflow and on amplify i will only build application not generate sourcemaps.

So @lforst can you please tell me how i generate and upload source maps with github action.

lforst commented 1 year ago

@gauravsapkal1 You can follow the manual CLI upload docs: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/#manual-setup

gauravsapkal1 commented 1 year ago

@lforst currently i am doing

name: Build Next.js App

on:
  push:
    branches:
      - sentry_implementation

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Sentry Release
      uses: getsentry/action-release@v1.0.0
      env:
        SENTRY_AUTH_TOKEN: ${{ secrets.NEXT_PUBLIC_SENTRY_AUTH_TOKEN }}
        SENTRY_ORG: ${{ secrets.NEXT_PUBLIC_SENTRY_ORG_NAME }}
        SENTRY_PROJECT: ${{ secrets.NEXT_PUBLIC_SENTRY_PROJECT_NAME }}
      with:
        environment: production

this way its marking release but in sourcemaps its not uploading anything only showing 0 value

Screenshot 2023-09-04 at 6 50 14 PM
gauravsapkal1 commented 1 year ago

Also I did one another method, there I build my nextjs app on github actions first which generate and upload sourcemaps, after that while building application on amplify I stops sourcemap generation and upload on amplify by setting disableServerWebpackPlugin: true disableClientWebpackPlugin:true. by this way sourcemaps generated during build process of github action getting upload to sentry but after application build on amplify its not getting able to track errors with proper stack trace form previously uploaded sourcemaps of github actions.

lforst commented 1 year ago

I recommend you go with the Sentry CLI route instead of the Sentry GitHub action and follow the troubleshooting guide if you face any issues: https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/

gauravsapkal1 commented 1 year ago

@lforst Yes gone through cli documentation and also implimented that and its uploading sourcemaps through github action, but on sentry dashboard its not able to track staktrace with this sourcemaps. My flow now looks like:-

  1. when i push commit in my github branch i my github action triggers and it builds nextjs app with sourcemaps and sentry-cli uploads that to sentry dashboard.
  2. After that Amplify also builds same nextjs app without generating and without uploading sourcemaps and deploys that app.
  3. So now when some error happens in my amplify deployed app its not able to track stack trace with help of sourcemaps uploaded through github actions. So I just wan to ask is my method wrong , does at each build sourcemaps necessary, or is there any standard which can create similar build every time
lforst commented 1 year ago

@gauravsapkal1 You need to upload the exact source files and source maps that you're deploying. Doing two separate builds and only uploading the source maps from one will therefore not work.

gauravsapkal1 commented 1 year ago

@lforst yes, but problem is when I generate source-maps on amplify my build getting failed because of amplify memory exceed issue. So is there any other way you can suggest to tackle this situation.

lforst commented 1 year ago

@gauravsapkal1 I don't know of any other way. Maybe you can increase the memory limit in amplify somehow?

gauravsapkal1 commented 1 year ago

its not possible in amplify its hard limit. Thank you @lforst for guidance

getsantry[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 remove the label Waiting for: Community, I will leave it alone ... forever!


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