Skip to content

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-module 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 🤷‍♂️

@mydea
Copy link
Member

mydea commented May 20, 2025

@timfish is this still something you want to merge at some point, or can/should we close this?

@timfish
Copy link
Collaborator Author

timfish commented Sep 4, 2025

Closing for now

@timfish timfish closed this Sep 4, 2025
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

2 participants