Content-Length: 349628 | pFad | https://github.com/getsentry/sentry-javascript/issues/15433

A1 @sentry/nuxt breaks Nuxt context for ~1% of requests · Issue #15433 · getsentry/sentry-javascript · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sentry/nuxt breaks Nuxt context for ~1% of requests #15433

Open
3 tasks done
maxtomczyk opened this issue Feb 17, 2025 · 9 comments
Open
3 tasks done

@sentry/nuxt breaks Nuxt context for ~1% of requests #15433

maxtomczyk opened this issue Feb 17, 2025 · 9 comments
Assignees
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK Waiting for: Community

Comments

@maxtomczyk
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

9.1.0

Framework Version

3.15.4

Link to Sentry event

No response

Reproduction Example/SDK Setup

const release = `${process.env.NUXT_PUBLIC_APP_NAME}@${ver.replace('v', '')}`

Sentry.init({
  dsn: process.env.NUXT_PUBLIC_SENTRY_DSN,
  environment: process.env.NUXT_PUBLIC_ENVIRONMENT,
  release,
  tracesSampleRate: 0.5,
  debug: true,
})

Steps to Reproduce

  1. Build Nuxt app
  2. Start server with node --import ./dist/apps/core/.output/server/sentry.server.config.mjs ./dist/apps/core/.output/server/index.mjs
  3. Run Grafana K6 to test

Expected Result

All requests are correctly handled.

Actual Result

About 1% of requests fails with 500 status code:

K6 results for node ./dist/apps/core/.output/server/index.mjs:

Image

K6 results for node --import ./dist/apps/core/.output/server/sentry.server.config.mjs ./dist/apps/core/.output/server/index.mjs:

Image

I spent the last few days trying to fix or at least find the cause of this issue. I discovered that the 500 status codes are caused by the nuxt instance unavailable error thrown from the pinia store setup function. It's not logged to console because setup function is called inside vue's runWithContext, which doesn't throw error.

Another clue is the fact that the issue doesn't occur with k6 simultaneity set to 1, which makes me believe it may be some race condition introduced by @sentry/node.

Also, commenting maybeInitializeEsmLoader function call in @sentry/node, while it's not a solution, maybe it will make it easier to find root cause.

I'm aware that this issue provides a small number of details, but unfortunately, I'm not able to share the codebase with you, however, I will be happy to provide you more details as needed.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 17, 2025
@github-actions github-actions bot added the Package: nuxt Issues related to the Sentry Nuxt SDK label Feb 17, 2025
@s1gr1d
Copy link
Member

s1gr1d commented Feb 17, 2025

Thanks for taking the time and looking into this!

  • Pinia: This is definitely something we can easily handle in the SDK
  • Potential Race Condition: As this issue does not occur with simultaneous users (VUs if I am correct?), it could definitely be a race condition. But I don't know where yet. The server-side adds a timeout for flushing events when they are serverless but you should not run into this here, as you need to run this in a serverless environment (code here).
  • Commenting maybeInitializeEsmLoader(): I am not sure what you mean here, can you elaborate?

@maxtomczyk
Copy link
Author

Thanks for replying that fast.

  • Potential Race Condition: You are correct, I meant VUs. Also, we don't use serverless for our applications.
  • Commenting maybeInitializeEsmLoader(): I meant modifying built @sentry/node to not call it:

Image

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 17, 2025
@s1gr1d
Copy link
Member

s1gr1d commented Feb 18, 2025

I know you meant commenting it like this :)
I was just wondering what you think would be the change and if you already tried it. Did you already try it?

You could either build the @sentry/node package on your machine with this change or just change this line (like you already did) in the built Sentry folder in the node_modules (you would have to do this in the cjs and esm folder of the build output - just to be sure).

@maxtomczyk
Copy link
Author

maxtomczyk commented Feb 18, 2025

It looks like I forgot to write about the results of commenting maybeInitializeEsmLoader. The issue doesn't occur with this code commented.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 18, 2025
@s1gr1d
Copy link
Member

s1gr1d commented Feb 18, 2025

Okay thank you, we'll look into this! :)

@maxtomczyk
Copy link
Author

I just successfully solved the issue in our apps by simply enabling the experimental asyncContext feature in the nuxt.config.ts. Although it doesn't address the root cause, it should help in identifying this error.

@s1gr1d
Copy link
Member

s1gr1d commented Feb 19, 2025

Okay this is interesting. Enabling asyncContext will make Nuxt use the Node AsyncLocalStorage API for managing the Nuxt context. It could be that the Nuxt context is relevant as well here, but tbh I am not sure how this relates 🤔

But since you wrote that you get the error nuxt instance unavailable it's probably a good choice to set asyncContext: true as this will often fix exactly those issues.

For Sentry's Node-part of the SDK, we need the AsyncLocalStorage to be available. However, the AsyncLocalStorage should be also available when asyncContext: false as it is just a Node feature. Or are you running this test in environments other than Node?

@maxtomczyk
Copy link
Author

I tested using Node.js 22.11.0. Since I'm not familiar with the @sentry/node code, I don't have much additional useful information to provide. However, considering the issue that the asyncContext flag addresses, one possible cause could be asynchronous code executing conditionally before calling a Nuxt function that requires the Nuxt context. Let me know if there's anything else I can clarify or provide.

@s1gr1d
Copy link
Member

s1gr1d commented Mar 20, 2025

Considering that the error message says Nuxt instance unavailable because the Sentry server config was loaded outside of the server environment (Nitro) as well.

@maxtomczyk Could you try running this again with 9.7.0?

With the PR #15749, the Sentry server config is not "leaking" out of Nitro into the Nuxt environment anymore.

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK Waiting for: Community
Projects
Status: Waiting for: Community
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/getsentry/sentry-javascript/issues/15433

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy