-
-
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
Add support for Next.js cache instrumentation #12888
Comments
asking in nextjs discussions about extending default cache handler: vercel/next.js#67677 |
So some initial thoughts after a brief look... We need to create some kind of cache wrapper that adds the instrumentation but this will only work for self-hosted. I guess hosted on Vercel is out of scope for this issue? Passing the module.exports = {
cacheHandler: require.resolve('./cache-handler.js'),
cacheMaxMemorySize: 0, // disable default in-memory caching
} I guess the default cache could be instrumented via |
...and whereas the Sentry docs warn about possible performance issues with |
Ok so it loads the cache implementation here: if (cacheHandler) {
CacheHandler = interopDefault(
await import(formatDynamicImportPath(dir, cacheHandler)).then(
(mod) => mod.default || mod
)
)
}
Passing around paths to modules like this is very inflexible so I'm hoping there's a good reason for it! So if we offered a solution that wraps the handler at this config point:
Assuming no bundler issues, the best I've got at this late hour is passing the user handler path via an environment variable 😂 module.exports = {
cacheHandler: sentryCacheWrapper(require.resolve('./cache-handler.js')),
cacheMaxMemorySize: 0, // disable default in-memory caching
} export function sentryCacheWrapper(userHandler: string): string {
process.env.__SENTRY_USER_CACHE_HANDLER_PATH = userHandler;
return require.resolve('./sentry-cache-handler.cjs');
}
const userHandler = require(process.env.__SENTRY_USER_CACHE_HANDLER_PATH);
export default class SentryCacheHandler {
function get(key) {
// do instrumentation here, etc
// return userHandler.get(key);
}
} It might be easier to use |
This would be worrying with arbitrary data (especially since stringifying certain primitives like booleans are not a good for the real world size), but because data is constrained to be Though looking at https://github.com/vercel/next.js/blob/fd5581d7ef58e4e925485b8b3a2b30ea8a482732/packages/next/src/server/response-cache/types.ts#L87, I guess stringifying some of these fields
I'm leaning toward this option as long as we only wrap |
I think I like the approach of using |
Yep, probably less prone to breakage and it looks like |
Problem Statement
We support manually instrumenting caching, but this is a pain to figure out: https://docs.sentry.io/platforms/javascript/guides/nextjs/tracing/instrumentation/custom-instrumentation/caches-module/
Solution Brainstorm
We should either
a) auto-instrument the Next.js cache via https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath
b) update the cache module docs if auto-instrumentation is not possible.
The text was updated successfully, but these errors were encountered: