-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(nextjs): Add excludeServerRoutes
config option
#6207
feat(nextjs): Add excludeServerRoutes
config option
#6207
Conversation
size-limit report 📦
|
78dc8b8
to
c98a180
Compare
4d699da
to
172f933
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Left just one small thought regarding compatibility with Next.js 13's new app
folder.
// Exclude certain serverside API routes or pages from being instrumented with Sentry. This option takes an array of | ||
// strings or regular expressions. | ||
// | ||
// NOTE: Pages should be specified as routes (`/animals` or `/api/animals/[animalType]/habitat`), not filepaths | ||
// (`pages/animals/index.js` or `.\src\pages\api\animals\[animalType]\habitat.tsx`), and strings must be be a full, | ||
// exact match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Just something we should maybe think about: I am wondering if we should have users include "pages/"
in the strings/regexes they provide here just to future-proof us against Next.js 13's app/
folder. However, the more I think about it it shouldn't matter, as the routes in the app/
folder will also just be routes like we have in the pages folder and I believe they can't collide - so we're probably good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good question, but I think you're right, a route is a route and you can't have two with the same route path. I also think that it's better that we abstract away the underlying file structure. That way, as users do move their routes from pages/
to app/
, they won't have to come and update this setting.
c98a180
to
d04f3bc
Compare
172f933
to
7ec84be
Compare
d04f3bc
to
054796b
Compare
7ec84be
to
0e98d62
Compare
054796b
to
3eeff43
Compare
0e98d62
to
a92e32f
Compare
…5789) This adds the new `excludeServerRoutes` option in the nextjs SDK (added in getsentry/sentry-javascript#6207) to the docs. It also pulls all of the auto-instrumentation config into its own section in the manual setup page. (Note: The only part of this which is actually new content is the `Opt Out of Auto-instrumentation on Specific Routes` section. Everything else is just stuff moving around.)
@lobsterkatie this doesn't seem to be working on the latest release.
My api route is using the Vercel OG package with the experimental-edge runtime. |
@zlwaterfield - you've got the new option in your webpack plugin options, where as it needs to be in the https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#extend-nextjs-configuration |
Wow I can't believe I missed that. Thank you for pointing that out. This PR is a life saver. |
…5789) This adds the new `excludeServerRoutes` option in the nextjs SDK (added in getsentry/sentry-javascript#6207) to the docs. It also pulls all of the auto-instrumentation config into its own section in the manual setup page. (Note: The only part of this which is actually new content is the `Opt Out of Auto-instrumentation on Specific Routes` section. Everything else is just stuff moving around.)
Currently, in the nextjs SDK, we inject the user's
Sentry.init()
code (by way of theirsentry.server.config.js
file) into all serverside routes. This adds a new option to thesentry
object innext.config.js
which allows users to prevent specific routes from being instrumented in this way. In this option, excluded routes can be specified using either strings (which need to exactly match the route) or regexes.Note: Heavily inspired by #6125. h/t to @lforst for his work there. Compared to that PR, this one allows non-API routes to be excluded and allows excluded pages to be specified as routes rather than filepaths. (Using routes a) obviates the need for users to add
pages/
to the beginning of every entry, b) abstracts away the differences between windows and POSIX paths, and c) futureproofs users' config values against underlying changes to project file organization.)Docs for this feature are being added in getsentry/sentry-docs#5789.
Fixes #6119.
Fixes #5964.
Fixes #5667.