Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(nextjs): Instrument cache handler #13124

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

Closed
timfish wants to merge 15 commits into develop from timfish/feat/nextjs-cache-handler-instrument

Conversation

Copy link
Collaborator

@timfish timfish commented Jul 30, 2024
edited
Loading

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!

This comment was marked as outdated.

timfish added 12 commits July 31, 2024 18:33
....com:getsentry/sentry-javascript into timfish/feat/nextjs-cache-handler-instrument
....com:getsentry/sentry-javascript into timfish/feat/nextjs-cache-handler-instrument
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 🤷‍♂️

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?

Copy link
Collaborator Author

timfish commented Sep 4, 2025

Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add support for Next.js cache instrumentation
2 participants

AltStyle によって変換されたページ (->オリジナル) /