Next.js

AppSignal for Node.js 3.0.0This integration requires AppSignal for Node.js 3.0.0 or higher.
Next.js 9.3.0This integration requires Next.js 9.3.0 or higher.

Default instrumentations can be disabled via the disableDefaultInstrumentations config option. You can read more about how to configure this in our Configuration Options documentation.

We're currently experiencing some technical issues with our Next.js integration. We're working to fix them and will update our documentation as soon as they're resolved. You can follow our changelog to keep up-to-date on AppSignal for Next.js integration changes or contact support if you'd like us to notify you when these technical issues have been resolved.

The AppSignal integration for Next.js.

It is recommended to be used with @appsignal/javascript and @appsignal/react on the client-side for full-stack performance monitoring and error tracking.

At this time, it's only possible to use this integration with a custom server script. The integration does not work when using the Next CLI (e.g. next start).

If you plan to use this in a serverless environment, we recommend using just @appsignal/javascript and the @appsignal/react integration.

Installation

When using a custom server script, Next.js is instrumented automatically by the AppSignal for Node.js package.

Usage with Express

You must add express as a dependency to your project. Then, create a server.js in your project root and add the following:

import { expressErrorHandler } from "@appsignal/nodejs";
import express from "express";
import { parse } from "url";
import next from "next";
// or: const { expressErrorHandler } = require("@appsignal/nodejs");
// or: const express = require("express");
// or: const { parse } = require("url");
// or: const next = require("next");
 
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const port = parseInt(process.env.PORT, 10) || 3000;
 
app
  .prepare()
  .then(() => {
    express()
      .use(handle)
      .use(expressErrorHandler())
      .listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`);
      });
  })
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });

Make sure to update your package.json to use the custom server and require the AppSignal configuration file:

"scripts": {
  "dev": "node server.js",
  "build": "next build",
  "start": "NODE_ENV=production node --require ./appsignal.cjs server.js"
}

Features

The Next.js integration will send AppSignal a trace for each request.

If the custom server uses Express, any errors raised when handling the request will be reported to AppSignal.

Need more help?

Contact us and speak directly with the engineers working on AppSignal. They will help you get set up, tweak your code and make sure you get the most out of using AppSignal.

Contact us

Start a trial - 30 days free

AppSignal is a great way to monitor your Ruby, Elixir & Node.js applications. Works great with Rails, Phoenix, Express and other frameworks, with support for background jobs too. Let's improve your apps together.

Start a trial