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

Nuxt 3.15.4 and Sentry Nuxt lead to Memory Leak

Open PhilippLupo opened this issue 4 months ago • 19 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/
  • [ ] 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/nuxt

SDK Version

10.8.0

Framework Version

10.8.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

Package Lock Versions:

 "node_modules/nuxt": {
      "version": "3.15.4",
      "resolved": "https://registry.npmjs.org/nuxt/-/nuxt-3.15.4.tgz",
      "integrity": "sha512-hSbZO4mR0uAMJtZPNTnCfiAtgleoOu28gvJcBNU7KQHgWnNXPjlWgwMczko2O4Tmnv9zIe/CQged+2HsPwl2ZA==",
      "license": "MIT",
 "node_modules/@sentry/nuxt": {
      "version": "10.8.0",
      "resolved": "https://registry.npmjs.org/@sentry/nuxt/-/nuxt-10.8.0.tgz",
      "integrity": "sha512-GdxA7LiVn2EouI2PxNNmHUwtYUrECxDCdW4ARiSgEoKf3/bt8AP7Fi2RvOw2OGVv4Iwn2irDZtbFApsEQqkwSg==",
      "license": "MIT",
      "dependencies": {
        "@nuxt/kit": "^3.13.2",
        "@sentry/browser": "10.8.0",
        "@sentry/cloudflare": "10.8.0",
        "@sentry/core": "10.8.0",
        "@sentry/node": "10.8.0",
        "@sentry/rollup-plugin": "^4.1.1",
        "@sentry/vite-plugin": "^4.1.0",
        "@sentry/vue": "10.8.0"
      },
      "engines": {
        "node": ">=18.19.1"
      },
      "peerDependencies": {
        "nuxt": ">=3.7.0 || 4.x"
      }
    },

modules: [
    ....
    '@sentry/nuxt/module',
],
import * as Sentry from '@sentry/nuxt';
const env = useRuntimeConfig().public.APP_ENV;

Sentry.init({
  // If set up, you can use your runtime config here
  // dsn: useRuntimeConfig().public.sentry.dsn,
  dsn: 'https://....',

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: env === 'prod' ? 0.2 : 1.0,

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // If the entire session is not sampled, use the below sample rate to sample
  // sessions when an error occurs.
  replaysOnErrorSampleRate: 1.0,

  // If you don't want to use Session Replay, just remove the line below:
  integrations: [Sentry.replayIntegration()],

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,

  environment: env,
});
import * as Sentry from '@sentry/nuxt';
import { config } from 'dotenv';

config();

const env = process.env.APP_ENV;

Sentry.init({
  dsn: 'https://.....',

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: env === 'prod' ? 0.2 : 1.0,

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
  environment: env,
});

Steps to Reproduce

I have got a project that is currently running on Nuxt 3.15.4 and wanted to add Sentry. Therefore I went to the official docs and went by installing it: https://nuxt.com/modules/sentry - nothing special.

Working locally in my DEV environment looks about fine, also the communication with Sentry and the dashboard all work fine.

As in the past I experienced some memory leaks with other Nuxt Modules i did the following:

  • npm run build
  • pm2-runtime .output/server/index.mjs
  • pm2 monit

Then I started my local loadtest by calling all possible url's and I saw the unusualy memory increase, which does not happen if sentry is not installed.

Expected Result

Without it's running pretty stable at around 300MB:

Image

Actual Result

After around 1-2 minutes my application uses already 2GB of memory with Nuxt Sentry (10.8.0) installed:

Image

PhilippLupo avatar Sep 08 '25 14:09 PhilippLupo

Hy, thanks for reaching out!

Can you upgrade to the latest version of Sentry? Maybe upgrading to the latest version already changes the outcome. If not, we'll have to dig into this.

And where do you deploy your application to? What OS is this?

s1gr1d avatar Sep 11 '25 11:09 s1gr1d

Noticed the same issue on "nuxt": "4.1.2" and "@sentry/nuxt": "10.12.0".

After rollback to "@sentry/vue": "10.12.0", the memory leak issue seems to be gone.

tomsdob avatar Sep 22 '25 07:09 tomsdob

Hello, as you said you used @sentry/vue: Did you only set up sentry.client.config.ts or did you previously also set it up for the server?

s1gr1d avatar Sep 22 '25 12:09 s1gr1d

@s1gr1d @sentry/vue was set up as a Nuxt plugin that runs only on the client side. @sentry/nuxt was set up according to the manual setup guide here: https://nuxt.com/modules/sentry.

tomsdob avatar Sep 22 '25 13:09 tomsdob

Okay thank you! I'll have a look into this.

s1gr1d avatar Sep 22 '25 14:09 s1gr1d

Any news on this? I was evaluating Sentry two weeks ago and was hit by this so had to postpone using Sentry.

bjerggaard avatar Oct 16 '25 08:10 bjerggaard

We fixed a potential memory leak in 10.14.0 via https://github.com/getsentry/sentry-javascript/pull/17712. Did anyone try 10.14.0 or newer?

Lms24 avatar Oct 16 '25 08:10 Lms24

@Lms24 I tried 10.20 on Nuxt 3 & Nuxt 4. Same problem.

khaled-logihub avatar Oct 20 '25 16:10 khaled-logihub

Thanks for trying it with the update! Then it's probably something different. We'll continue to look into this.

s1gr1d avatar Oct 21 '25 07:10 s1gr1d

May I ask what is the testing methodology you are using?

I ran some tests on the latest release by load testing a blank Nuxt app with and without the SDK and the memory leak is there in either case, while the memory usage baseline is higher with Sentry enabled but that is to be expected as an overhead of the Node.js instrumentation under the hood. After a 60~120 seconds window, most of the memory gets released back by GC in either case.

In my tests I used autocannon to perform a load test of 1k requests/second sustained over 30 seconds against the app and noticed no significant difference in memory allocations.

It would be very helpful if you can take a heap snapshot of with/without Sentry if you can see this locally and send them our way.

logaretm avatar Oct 29 '25 09:10 logaretm

Not sure if this helps but I'm seeing this in production -added "@sentry/nuxt": "^10.22.0" and then production started crashing a few times a day :)

Image

Chippd avatar Nov 06 '25 00:11 Chippd

@Chippd How do you set up Sentry in your Nuxt application? And which version of Nuxt and Vite are you using?

s1gr1d avatar Nov 06 '25 09:11 s1gr1d

@Chippd How do you set up Sentry in your Nuxt application?

I used the wizard as documented here: https://docs.sentry.io/platforms/javascript/guides/nuxt/

And which version of Nuxt and Vite are you using?

"nuxt": "3.20.0" and for vite: Vite 6.3.5 (Nuxt builder); additional Vite 5.4.14 from some plugins present.

Here's my sentry.client.config.ts

import * as Sentry from "@sentry/nuxt";

const config = useRuntimeConfig().public;

Sentry.init({
  // If set up, you can use your runtime config here
  // dsn: useRuntimeConfig().public.sentry.dsn,
  dsn: config.sentry.dsn,

  // Tunnel option routes Sentry events through our own endpoint to avoid ad-blockers
  // Tunnel endpoint has fallback mechanism for dev server compatibility
  // tunnel: "/api/tnl",

  environment: config.ENV,

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: config.SENTRY_TRACES_SAMPLE_RATE,

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: config.SENTRY_REPLAY_SAMPLE_RATE,
  
  // If the entire session is not sampled, use the below sample rate to sample
  // sessions when an error occurs.
  replaysOnErrorSampleRate: config.SENTRY_ERROR_REPLAY_SAMPLE_RATE,
  
  // If you don't want to use Session Replay, just remove the line below:
  integrations: [Sentry.replayIntegration()],

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // Enable sending of user PII (Personally Identifiable Information)
  // https://docs.sentry.io/platforms/javascript/guides/nuxt/configuration/options/#sendDefaultPii
  sendDefaultPii: true,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

Here's my sentry.server.config.ts

import * as Sentry from "@sentry/nuxt";
 
const config = useRuntimeConfig().public;

Sentry.init({
  dsn: config.sentry.dsn,

  // Tunnel option routes Sentry events through our own endpoint to avoid ad-blockers
  // For server-side, we need to use an absolute URL
  // Tunnel endpoint has fallback mechanism for dev server compatibility
  // tunnel: `${config.DOMAIN && config.ENV !== 'development' ? `https://${config.DOMAIN}` : 'http://localhost:3000'}/api/tnl`,

  environment: config.ENV,

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: config.SENTRY_TRACES_SAMPLE_RATE,

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // Enable sending of user PII (Personally Identifiable Information)
  // https://docs.sentry.io/platforms/javascript/guides/nuxt/configuration/options/#sendDefaultPii
  sendDefaultPii: true,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

Also, I've updated the npm start command as per the docs: "start": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs",

Chippd avatar Nov 06 '25 19:11 Chippd

Thank you, do you see the same memory leak if you disable specific integrations? Like the replay integration and the associated config options, or removing the enableLogs option or tracesSampleRate?

s1gr1d avatar Nov 07 '25 12:11 s1gr1d

I'm working through some things to narrow it down. Incidentally I found this issue for memory leaks in Nuxt itself due to Vue: https://github.com/nuxt/nuxt/issues/32240#issuecomment-2951262657

So my particular problem could be either. I'll remove things one by one and check - first would be to pin Vue to 3.5.13 and see what happens.

Chippd avatar Nov 07 '25 19:11 Chippd

Sorry for the noise I added to this, but my particular problem was solved by reverting to a previous version of Nuxt I know worked for me - 3.17.2 (the workaround of overriding Vue as suggested in this comment was causing me other issues)

I can confirm that I'm now seeing flat memory usage, with no change to my Sentry implementation.

Image

Chippd avatar Nov 07 '25 23:11 Chippd

Thank you so much for taking the time and trying to track that down with your own implementation!

To all other people who commented on this issue (@PhilippLupo @tomsdob @bjerggaard @khaled-logihub): Do you still experience memory leaks or can that be resolved with overriding the Vue version like mentioned above? To avoid creating noise in the comments, please just react with 👍 if it works for you now and with 👎 if you still experience the issue (with the Vue override).

As @logaretm mentioned above, he was not able to reproduce this so this might not be a Sentry-only problem.

However, if your issue persist, please comment your installed versions (from the lock file) of Nuxt, Vue and Nitro (you should also see the Nuxt and Nitro version when starting the build).

s1gr1d avatar Nov 10 '25 09:11 s1gr1d

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 🥀

getsantry[bot] avatar Dec 05 '25 08:12 getsantry[bot]