How to Integrate SecureNow with Your Next.js Application
Complete guide to adding enterprise-grade security monitoring to your Next.js app with SecureNow. Learn automatic setup, manual configuration, and best practices for production deployment.


2026 update: SecureNow v8 runtime credentials
New integrations should run npx securenow login or npx securenow app connect. Local SDK config lives in .securenow/runtime.json, and telemetry ingestion now requires the snk_live_... runtime API key. The SDK no longer reads SECURENOW_APPID / SECURENOW_INSTANCE or any other SECURENOW_* variable except SECURENOW_CREDENTIALS and SECURENOW_DISABLED. For production, mount the tokenless runtime export generated by npx securenow credentials runtime --env production.
Introduction
Next.js is one of the most popular React frameworks for building production-ready web applications, but securing these applications requires proper monitoring and threat detection. In this comprehensive guide, you'll learn how to integrate SecureNow with your Next.js application to get real-time security monitoring, performance analytics, and automatic threat detection.
SecureNow provides automatic instrumentation for Next.js applications using OpenTelemetry, giving you deep insights into API routes, server-side rendering, and server components without requiring code changes. The best part? Setup takes less than 30 seconds with the SecureNow CLI!
Quick Installation (30 Seconds)
The fastest way to get started is to install SecureNow with npm. Then two CLI commands connect your app, detect that you're using Next.js and create the instrumentation file for you.
npm install securenow@latest
npx securenow login
npx securenow initđ Automatic Setup
npx securenow login opens your browser to pick or create your app and writes .securenow/runtime.json. npx securenow init then detects your Next.js project and creates all necessary files for you!
That's it! init creates the instrumentation.ts file at your project root with all the necessary configuration. The Configuration section below shows where your settings live (there are no environment variables to set).
Manual Setup (Alternative Method)
If you skipped the automatic setup above, or prefer to set things up manually, you have two options:
Option 1: Use the CLI (Recommended)
Run the SecureNow initialization command to create the instrumentation file:
npx securenow initThis command will create the instrumentation.ts file at your project root with the correct configuration for Next.js, and add the next.config settings SecureNow needs.
Option 2: Create the File Manually
Create a file named instrumentation.ts in your project root directory (at the same level as your next.config.js file):
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
try {
const securenowNext = await import('securenow/nextjs');
const registerSecureNow = securenowNext.registerSecureNow || securenowNext.default?.registerSecureNow;
registerSecureNow({ captureBody: true });
await import('securenow/nextjs-auto-capture');
} catch (error) {
console.error('[securenow] SecureNow did not start; the app is running without it:', error);
}
}
}This instrumentation file is automatically loaded by Next.js when your application starts, enabling SecureNow to monitor all requests, API routes, and server-side operations.
Then keep SecureNow out of the server bundle in next.config.js (Next.js 15 and 16; for Next.js 14, see Step 2 below):
module.exports = {
serverExternalPackages: ['securenow'],
outputFileTracingIncludes: {
'/*': ['./node_modules/securenow/**/*'],
},
}đ File Location
The instrumentation.ts file must be placed at the root of your project, not inside the app or pages directory. If you're using the src directory structure, place it inside src, next to app or pages.
Configuration
Step 1: Check the Runtime Config
There is no .env.local to write: SecureNow does not read its settings from environment variables. npx securenow login saves them in .securenow/runtime.json in your project root, and every setting has a secure default. The parts that matter look like this:
{
"apiKey": "snk_live_...",
"app": { "key": "b9c8d7e6-f5a4-3210-9876-543210fedcba", "name": "my-nextjs-app" },
"config": {
"logging": { "enabled": true },
"capture": { "body": true }
}
}Configuration Parameters Explained
app.key
Your app's unique key, written by login. The SDK uses it as the service name, which is how the SecureNow dashboard finds this application's traces.
apiKey
The runtime API key that authenticates telemetry ingestion and firewall sync. Telemetry goes to the SecureNow ingestion gateway and is routed by the app key, so there is no collector URL to set; a self-hosted collector goes in config.otel.endpoint.
â ī¸ Secrets
Never commit .securenow/runtime.json or .securenow/admin.json to version control. npx securenow init adds them to .gitignore without ignoring the whole .securenow/ folder, but always double-check before committing.
Step 2: Enable Instrumentation Hook (Next.js 14 Only)
If you're using Next.js 14, enable the experimental instrumentation hook and keep SecureNow external in your next.config.js file (from securenow 8.25.0, npx securenow init writes this for you; tested end to end on Next.js 14.2.35 with next start and standalone output). This step is not required for Next.js 15 and above, where instrumentation hooks are enabled by default.
module.exports = {
experimental: {
instrumentationHook: true,
serverComponentsExternalPackages: ['securenow'],
outputFileTracingIncludes: {
'/*': ['./node_modules/securenow/**/*'],
},
},
}If you already have other configuration in your next.config.js, simply add these experimental properties to your existing configuration object.
âšī¸ Next.js 15+ Users
If you're using Next.js 15 or later, you can skip this step entirely! Instrumentation hooks are stable and enabled by default in Next.js 15+, so the only config you need is the serverExternalPackages and outputFileTracingIncludes settings shown above.
Running Your Application
Once you've completed the setup, start your Next.js development server:
npm run devFor production deployments, build and start your application as usual:
npm run build
npm startVerification
When your application starts, look for the SecureNow confirmation message in your terminal:
[securenow] OpenTelemetry started for Next.jsIf you see this message, congratulations! SecureNow is now monitoring your Next.js application. Navigate to a few pages in your application to generate some traces, then check your SecureNow dashboard to see the incoming telemetry data.
â Next Steps
Open your SecureNow dashboard and look for traces from your application (identified by your app key, the app you picked at login). You should see traces for page loads, API routes, and server-side operations within a few seconds of using your application.
What SecureNow Monitors in Next.js
SecureNow provides comprehensive monitoring for your Next.js application, including:
- API Routes: Automatic instrumentation of all API endpoints in your app/api/ or pages/api/ directories
- Server Components: Monitoring of React Server Components and data fetching operations
- Server-Side Rendering (SSR): Performance tracking for getServerSidePropsand server component renders
- Static Generation: Monitoring of getStaticProps and generateStaticParams functions
- Database Queries: Automatic detection of SQL injection attempts and slow queries
- External API Calls: Tracking of fetch requests, including response times and error rates
- Authentication Events: Monitoring of login attempts, session management, and authorization failures
- Error Tracking: Automatic capture of unhandled errors and exceptions with full stack traces
- Performance Metrics: Response times and error rates for every server-side request
- Security Threats: Real-time detection of SQL injection, XSS, CSRF, and other attack patterns
Deployment to Production
Vercel Deployment
If you're deploying to Vercel, which cannot mount a credentials file, add one secret environment variable in the Vercel dashboard:
- Go to your project settings in the Vercel dashboard
- Navigate to the "Environment Variables" section
- Add SECURENOW_CREDENTIALS with the value printed by npx securenow credentials runtime --env production --format env
- Make sure to add it for Production, Preview, and Development environments as needed
- Redeploy your application for the changes to take effect
On Vercel, SecureNow exports traces through @vercel/otel. This path has not been tested end to end yet, and the firewall has not been verified on Vercel serverless functions.
Docker Deployment
For Docker deployments, mount the production credentials file (written by npx securenow credentials runtime --env production) as .securenow/credentials.json in the app folder, for example with docker-compose.yml. With output: 'standalone', put it next to server.js:
# docker-compose.yml
services:
nextjs-app:
image: my-nextjs-app
volumes:
- ./.securenow/credentials.production.json:/app/.securenow/credentials.json:ro
ports:
- "3000:3000"Other Platforms
For other deployment platforms (AWS, Azure, Google Cloud, etc.), put the same credentials file at .securenow/credentials.json in the app folder. Where you can't mount a file, store the SECURENOW_CREDENTIALS value printed by npx securenow credentials runtime --env production --format env as a secret environment variable in your platform's configuration.
Advanced Configuration
Service Name and Log Level
The service name is your app key, which is how the dashboard finds your traces, so leave it as it is. Other settings go in the config block of .securenow/runtime.json, not in environment variables, for example the OpenTelemetry log level:
{
"config": {
"otel": { "logLevel": "info" }
}
}Multiple Environments
Next.js loads different environment files for different deployment stages:
- .env.local - Local development
- .env.development - Development environment
- .env.production - Production environment
Your SecureNow settings stay in .securenow/, not in these files. To separate environments in the dashboard, tag each deployment instead: npx securenow credentials runtime --env production writes config.runtime.deploymentEnvironment into the production credentials, and production, staging, preview, local and test all work.
Best Practices
Security
- Never commit .env.local or other environment files containing sensitive configuration to version control
- Use different application IDs for development, staging, and production environments
- Restrict access to your SecureNow instance endpoint using firewall rules or VPN
- Regularly review your SecureNow dashboard for security alerts and anomalies
Performance
- SecureNow is designed to have minimal performance impact (typically <1% overhead)
- Monitor your application's performance metrics in the SecureNow dashboard
- For high-traffic applications, consider adjusting sampling rates (contact support for guidance)
- Use SecureNow's performance insights to identify and optimize slow API routes and database queries
Development Workflow
- Keep SecureNow enabled during development to catch issues early
- Use the dashboard to debug API issues and trace request flows
- Set up custom alerts for critical errors in production
- Review security alerts regularly and incorporate fixes into your development cycle
Troubleshooting
No Traces Appearing in Dashboard
If you're not seeing any traces in your SecureNow dashboard:
- Verify the success message appears in your terminal: [securenow] OpenTelemetry started for Next.js
- Run npx securenow doctor from the project root to check .securenow/runtime.json and the connection to SecureNow
- Ensure ingest.securenow.ai is reachable from your application's network
- Try making a few requests to your application to generate traces
- Check your application logs for any SecureNow error messages
Instrumentation Hook Not Working (Next.js 14)
If you're using Next.js 14 and the instrumentation isn't working:
- Verify you've added experimental.instrumentationHook: true to next.config.js
- Restart your development server after modifying next.config.js
- Clear your .next build cache and rebuild: rm -rf .next && npm run dev
Build Errors
If you encounter build errors after adding SecureNow:
- Ensure your instrumentation.ts file is at the project root (or in src/ if you use one), not inside app/ or pages/
- If using JavaScript instead of TypeScript, name the file instrumentation.js
- Check that you're importing from securenow/nextjs, not just securenow
- Verify your Next.js version is 14 or higher (SecureNow is tested on Next.js 14.2, 15.5 and 16.4)
Dashboard Features
Once your application is sending traces to SecureNow, you can access these powerful features in your dashboard:
- Real-Time Trace Viewer: See every request flowing through your application in real-time
- Performance Analytics: Identify slow API routes, database queries, and external API calls
- Security Alerts: Get instant notifications about potential security threats and attack attempts
- Error Tracking: Comprehensive error reports with stack traces and request context
- Custom Dashboards: Create custom views and charts for your specific monitoring needs
- Alert Rules: Set up custom alerts based on error rates, response times, or security events
- Trace Search: Powerful search and filtering to find specific requests or investigate issues
- API Analytics: Detailed analytics for each API endpoint, including usage patterns and performance
Conclusion
Congratulations! You've successfully integrated SecureNow with your Next.js application. Your app now has enterprise-grade security monitoring, performance tracking, and automatic threat detection built right in.
SecureNow works transparently in the background, monitoring every request, API call, and database query without requiring any changes to your application code. The integration is zero-overhead in most cases, and the insights you gain from the telemetry data will help you build more secure, reliable, and performant applications.
As you continue developing your Next.js application, SecureNow will automatically adapt to your changes, monitoring new routes, API endpoints, and features as you add them. Make sure to check your dashboard regularly for security alerts, performance insights, and error reports.
For more advanced features, custom integrations, or enterprise support, visit our comprehensive documentation or reach out to our team at support@securenow.ai.
Recommended reading
A step-by-step account takeover investigation in plain English: the ten questions to ask, where each answer lives in your logs, traces and security events, and what to check before you call it closed.
Oct 28
Block one IP, a CIDR range, or a single route and method in a Node.js app within seconds, with no code change: setup, scoping, CLI, MCP, verification and undo.
Oct 27One login, 100 rotating IPs: a 10-per-minute-per-IP limit let 275 of 275 requests through. How to spot rotation in your traffic and what to key your limits on.
Oct 27