getsentry / sentry-javascript

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

Not working from Next.js middleware (edge runtime) when not using src folder #11840

Closed YoonIN closed 1 week ago

YoonIN commented 3 weeks ago

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

I created two situations in the monorepo.

  1. nextjs project without src
  2. nextjs project with src

When both captureException and captureMessage are executed in middleware, they do not work in projects without src, but work in projects with src.

According to the issue in that link, it says that the issue has been resolved, but is the issue not resolved?

This link here is my sample.

Expected Result

The middleware sentry must operate in both projects.

Actual Result

Sentry operates in middleware only for projects with src.

Product Area

Unknown

Link

https://github.com/YoonIN/next-middleware-test

DSN

No response

Version

No response

getsantry[bot] commented 3 weeks ago

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] commented 3 weeks ago

Routing to @getsentry/product-owners-issues for triage ⏲️

s1gr1d commented 3 weeks ago

Hello and thanks for writing! First, thank you for the reproduction repo 🙌🏻

I tested the examples and for me, only captureException was not showing up in Sentry when using next dev. When creating a production build (next build and next start), everything was showing up in Sentry. image

In general, our SDKs are optimized for production builds. Can you tell me which command you were using when starting the application? And does using the production build for you also leads to issues not showing up?

YoonIN commented 2 weeks ago

Sorry for the late reply.

As a result, it wasn't a problem with the src path like you said.

Our problem was that we had disabled the sideEffect.

Therefore, Sentry configuration files were treated as exceptions in the sideEffect rule.

package.json
...
"sideEffects": [
    "./sentry.client.config.js",
    "./sentry.edge.config.js",
    "./sentry.server.config.js"
  ],
...

Thank you for your reply.

s1gr1d commented 2 weeks ago

Were you able to run your example now? And did you have to add the files to sideEffects to make it work or is this the code example from where it did not work?

YoonIN commented 2 weeks ago

Your example worked fine. In our production service, the problem occurred because we disabled sideEffects, and we had to exclude sentry files from sideEffects.

s1gr1d commented 1 week ago

This means you could fix it? :) I will close the issue then, but please reopen it if you still experience issues!