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

feat(nextjs): Instrument cache handler #13124

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Jul 30, 2024

Closes #12888

The nextjs custom cache handler is loaded via dynamic import, therefore to wrap its exported class we use import-in-the-middle which is already a dependency of @sentry/node.

Since nextjs is CJS, you can use a sub-modules path to instrument the default handler by adding it as a custom cache handler like this:

module.exports = {
  cacheHandler: require.resolve('next/dist/server/lib/incremental-cache/file-system-cache.js'),
  cacheMaxMemorySize: 0,

Needs tests!

@timfish

This comment was marked as outdated.

@timfish
Copy link
Collaborator Author

timfish commented Aug 15, 2024

Ok, so a bit of an update of where I've got to...

I've got this PR working in a demo app via yarn link:

image

...but in the e2e tests, import-in-the-middle is getting bundled which stops it from working. I'm using the serverExternalPackages config option (experimental.serverComponentsExternalPackages in < Next v15) which should be able to add import-in-the-middle to webpack externals but this doesn't appear to work in combination with pnpm when import-in-the-middle is a sub-dependency:

I've opened an issue to include import-in-the-middle in the next.js default server externals because it will never work when bundled but I kinda doubt this will actually fix the issue with pnpm 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Next.js cache instrumentation
1 participant