NestJS
Vigilon monitors NestJS apps through @vigilon/node: add one flag to your start command and every request is traced with its route, database queries and outgoing calls. Nest catches errors and sends the 500 response itself, so add one global exception filter to see their stack traces.
Start Vigilon with your Nest app
Install @vigilon/node and set your API key as in the Node.js quickstart. Then add the --import flag to the script that starts your built app. Nest builds to dist/main.js by default:
{
"scripts": {
"start:prod": "node --import @vigilon/node/register dist/main.js"
}
}
No module or provider is needed. Nest runs on Express by default (@nestjs/platform-express), and Vigilon traces Express, so it traces your Nest app. Nest's default build is CommonJS, where --require @vigilon/node/register works as well; Vigilon's own NestJS apps start that way.
What a request looks like
Each request becomes a trace named after its Nest route template, for example GET /v1/projects/:projectId/error-groups, so all requests to one route land on one endpoint. Inside it you see Express spans for middleware such as corsMiddleware and jsonParser, one request handler span for the route, then the database queries (for example pg.query) and outgoing HTTP calls the request made.
There are no separate spans for controllers, guards, interceptors or pipes. Their time is counted inside the request handler span. The full list of libraries Vigilon traces is on What Vigilon tracks.
Record errors with a global exception filter
When a controller or service throws, Nest's exception layer catches the error and sends the response itself. The request is still recorded as failed, but Vigilon never sees the error, so the failed request has no error type, message or stack trace. Add a global filter that calls recordException and then hands the error back to Nest:
import { ArgumentsHost, Catch, HttpException } from "@nestjs/common";
import { BaseExceptionFilter } from "@nestjs/core";
import { recordException } from "@vigilon/node";
@Catch()
export class VigilonExceptionFilter extends BaseExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const expected =
exception instanceof HttpException && exception.getStatus() < 500;
if (!expected) {
recordException(exception);
}
super.catch(exception, host);
}
}
Register it once in main.ts:
import { HttpAdapterHost, NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { VigilonExceptionFilter } from "./vigilon-exception.filter";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(new VigilonExceptionFilter(httpAdapter));
await app.listen(3000);
}
bootstrap();
Nest still builds the response, so your clients see no change. The filter skips HttpExceptions below 500, such as NotFoundException or a failed validation, because those are answers your app meant to give, not errors. Every other error, including a plain throw new Error(), is recorded and grouped in your error groups.
Without the filter, errors thrown in Nest appear only as failed requests with no stack trace. If you already have a global filter, add the recordException(exception) call to it instead of adding a second one.
Scheduled tasks and workers
Jobs are not detected on their own, in Nest or elsewhere. Wrap the body of each run in withJobMonitor inside your service. With @nestjs/schedule, that is the method that carries @Cron:
import { Injectable } from "@nestjs/common";
import { Cron } from "@nestjs/schedule";
import { withJobMonitor } from "@vigilon/node";
@Injectable()
export class ReportsService {
@Cron("0 3 * * *")
async nightlyReport() {
await withJobMonitor(
{ name: "nightly-report", schedule: "0 3 * * *" },
() => this.buildNightlyReport(),
);
}
private async buildNightlyReport() {
// ...
}
}
Each run gets its own trace and appears as a job run. The schedule option uses the same cron expression, so Vigilon can tell you when a run is missed. Queue consumers and long-running worker loops work the same way: wrap one unit of work, not the whole loop. See Background jobs for BullMQ, missed runs and run names.