Koa.js

Our 2.x integration is deprecated, please upgrade to 3.x. Migration information is available here.

The AppSignal for Node.js integration for Koa (koa) v2.0.0+.

Installation

The @appsignal/koa is not compatible with the 3.x Node.js integration.

Our migration guide. explains how you can upgrade your Koa.js integration from 2.x to 3.x.

Add both the @appsignal/nodejs and @appsignal/koa packages to your package.json. Then, run yarn install/npm install.

You can also add these packages to your package.json on the command line:

yarn add @appsignal/nodejs@2 @appsignal/koa
npm install --save @appsignal/nodejs@2 @appsignal/koa

You can then import and use the package in your app.

Usage

The module includes an AppSignal intrumentation plugin for automatically instrumenting the middlewares or routes of your application.

// AT THE VERY TOP OF THE ENTRYPOINT OF YOUR APPLICATION...
 
const { Appsignal } = require("@appsignal/nodejs");
 
const appsignal = new Appsignal({
  active: true,
  name: "<YOUR APPLICATION NAME>",
  pushApiKey: "<YOUR API KEY>", // Note: renamed from `apiKey` in version 2.2.5
});
 
appsignal.instrument(require("@appsignal/koa"));
 
// ...ALL THE REST OF YOUR IMPORTS AND CODE GO HERE!
 
const Koa = require("koa");
const Router = require("@koa/router"); // @koa/router is also supported out of the box!
 
const app = new Koa();
 
// Add error handling
 
app.on("error", (error) => {
  appsignal.tracer().setError(error);
});

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