Instrumentations load by scope

While AppSignal automatically instruments code executed inside the request handlers of supported HTTP frameworks, there are scenarios where you may need to use helper functions to manually instrument AppSignal, for example in a one-off script or before your application is built.

In such scenarios we recommend using the instrumentationsLoaded() helper function, which returns a promise to ensure that theinstrumentation is ready to start reporting to AppSignal.

You only need to wrap your custom instrumentation helper calls within a promise, not your entire codebase. There are two ways of doing this depending on your Node.js configuration:

Using import syntax

When using the ES import syntax, you need to call await before using any custom instrumentation, like in the example below:

import { sendError, instrumentationsLoaded } from "@appsignal/nodejs";
await instrumentationsLoaded();
sendError(new Error("Test error"));

Using require syntax

When using the require syntax, you need to call .then() on the promise returned by instrumentationsLoaded(), like in the example below:

const { instrumentationsLoaded, sendError } = require("@appsignal/nodejs");
instrumentationsLoaded().then(() => {
  sendError(new Error("Test 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