Next.js is a JavaScript framework for building server-side rendered and statically generated web applications. With the APM Insight Next.js agent, you can monitor the back-end performance of your Next.js applications in Applications Manager, including key metrics, middleware execution, and pre-rendered HTML tracking.
Syntax:npm install <Next.js-Agent-extracted-path>/source
Example:npm install /users/joe/source
If you want to deploy APM Insight agent to all the Next.js applications on the computer, use the global option via -g flag.
Syntax:npm install -g <Next.js-Agent-extracted-path>/source
Example:npm install -g /users/joe/source
This will create an APM Insight directory under node_modules.
"dependencies": {
"@apminsight/next": "^1.2.5",
"next": "latest"
}
You can configure the APM Insight Next.js agent using one of the following methods.
Modify the scripts section of your package.json file to include the NODE_OPTIONS environment variable, which preloads the @apminsight/next middleware.
"scripts": {
"dev": "NODE_OPTIONS='-r @apminsight/next' next",
"build": "next build",
"start": "NODE_OPTIONS='-r @apminsight/next' next start"
}
Add the require statement for @apminsight/next before any other module in your application start file.
require('@apminsight/next')
/* ... the rest of your program ... */
next build may cause issues and increase bundle size unnecessarily. If you are using a custom Next.js server and not running your application via the Next CLI, start your application with the -r flag to preload the agent.
node -r @apminsight/next your-start-file.js
Create a new file named apminsightnode.json in the directory where you run the application and add the following configuration.
{
"licenseKey": "[LICENSE-KEY]",
"appName": "[APPLICATION-NAME]",
"port": "[APPLICATION-PORT]",
"apmHost": "[APM-HOST-NAME]",
"apmPort": "[APM-SSL-PORT]"
}
If you are using a proxy, add the proxy settings to the configuration file.
{
"licenseKey": "[LICENSE-KEY]",
"appName": "[APPLICATION-NAME]",
"port": "[APPLICATION-PORT]",
"apmHost": "[APM-HOST-NAME]",
"apmPort": "[APM-SSL-PORT]",
"proxyServerHost": "[PROXY-SERVER]",
"proxyServerPort": "[PROXY-PORT]",
"proxyAuthUser": "[PROXY-USERNAME]",
"proxyAuthPassword": "[PROXY-PASSWORD]"
}
Restart your application and carry out a few transactions. Navigate to the APM tab in Applications Manager to view the back-end performance metrics for your Next.js application.
You can also integrate the APM Insight Next.js agent into your Kubernetes application using initContainers. For step-by-step instructions, refer to the APM Insight integration for Next.js in Kubernetes guide.
It allows us to track crucial metrics such as response times, resource utilization, error rates, and transaction performance. The real-time monitoring alerts promptly notify us of any issues or anomalies, enabling us to take immediate action.
Reviewer Role: Research and Development