Conditional Instrumentation: Environment-based Control for Next.js Instrumentation API #75129
JamesRobertWiseman
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
Non-Goals
Background
The instrumentation API was stabilized in Next.js 15, providing a way to execute code when a new Next.js server instance starts. Currently, developers need to implement manual environment checks within the instrumentation file.
Starting from Next.js's recommended code:
To disable instrumentation in development, developers must add additional environment checks:
This approach, while functional, leads to:
A more elegant solution is needed to handle environment-specific instrumentation.
Proposal
Implement either:
disableInstrumentation
configuration option innext.config.js
that accepts a boolean or function returning boolean:instrumentation.prod.ts|js
- Only runs in productioninstrumentation.dev.ts|js
- Only runs in developmentinstrumentation.ts|js
- Runs in all environments (maintaining backward compatibility)I'm interested in contributing to the implementation of this feature. The preferred approach would be option 1, as it provides more flexibility and maintains the single file convention while allowing for simple environment control.
Beta Was this translation helpful? Give feedback.
All reactions