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.
Install
npm install @naijacloud/argusStart
Start your app with the Argus flag, so it loads before express:
ARGUS_DSN=https://<public key>@argus-in.naijacloud.com/<project id> node --import @naijacloud/argus/register app.jsExpress catches errors from your routes itself, so they never reach Node's uncaught-error hook. Add the Argus error handler after your routes:
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
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
traceparentheader from the caller continuing its trace. - Outgoing
fetch()calls as child spans, andconsolecalls as breadcrumbs.
Logs, metrics and traces
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
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:
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.