Naijacloud
Docs

Express

Express apps use the Node.js package. Start with the Argus flag so it loads before express, then add one error handler after your routes.

4 min read

Install

Install
bash
npm install @naijacloud/argus

Start

Start your app with the Argus flag, so it loads before express:

Start
bash
ARGUS_DSN=https://<public key>@argus-in.naijacloud.com/<project id> node --import @naijacloud/argus/register app.js

Express catches errors from your routes itself, so they never reach Node's uncaught-error hook. Add the Argus error handler after your routes:

app.js
js
import express from 'express'; import { argusErrorHandler } from '@naijacloud/argus'; const app = express(); app.get('/boom', () => { throw new Error('Card declined'); }); app.use(argusErrorHandler()); app.listen(3000);

The handler reports the error with the request's method and URL (without its query string), then passes it on, so your own error handlers still run.

On Naijacloud, the service's Send errors to Argus switch sets the DSN, release and environment, so the start command needs only the flag: node --import @naijacloud/argus/register app.js.

Send a test event

Send a test event
bash
npx @naijacloud/argus test --dsn https://<public key>@argus-in.naijacloud.com/<project id>

It sends one test event and says whether Argus accepted it. Without --dsn it uses ARGUS_DSN.

What it captures

  • Route errors, through argusErrorHandler().
  • Uncaught exceptions and unhandled rejections outside your routes.
  • Every request, traced, with a traceparent header from the caller continuing its trace.
  • Outgoing fetch() calls as child spans, and console calls as breadcrumbs.

Logs, metrics and traces

Logs, metrics and traces
js
import { log, metrics, trace } from '@naijacloud/argus'; app.post('/pay', async (req, res) => { log.info('payment started', { orderId: req.body.orderId }); metrics.count('payments.started', 1, { method: 'card' }); await trace('charge card', async (span) => { span?.setAttribute('provider', 'paystack'); await paystack.charge(req.body); }); res.send('ok'); });

Logs and spans written inside a request carry its trace id. Logs are sent every 5 seconds and metrics every 10. More in Node.js.

Cron check-ins and feature flags

Cron check-ins and feature flags
js
import { cron, flags } from '@naijacloud/argus'; // Create the monitor in Argus first. await cron.withMonitor('nightly-invoices', () => sendInvoices()); if (await flags.isOn('new-checkout', req.user.id)) { // … }

withMonitor reports the start, then success or failure. A flag check returns your fallback (false here) if Argus can't be reached.

Release and environment

Set ARGUS_RELEASE (your commit) and ARGUS_ENVIRONMENT next to ARGUS_DSN. The SDK falls back to SENTRY_RELEASE and SENTRY_ENVIRONMENT, and the environment is production when none is set.

Privacy

Passwords, tokens, cookies, card numbers and other secrets are replaced with [Filtered] before they leave your app, query strings are removed from URLs, and the user's IP address isn't sent. To change or drop events with beforeSend, start the SDK with init() instead of the flag. See Node.js privacy.

Already on Sentry

Keep @sentry/node. In your Sentry.init call, change the dsn line:

Sentry.init
js
dsn: 'https://<public key>@argus-in.naijacloud.com/<project id>',

Source maps

Stack traces point at the files Node runs. If you bundle or minify your code, upload its maps as described in Source maps.