Skip to main content

NestJS

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

@bugsee/nestjs adds a request context, an http.server transaction and error reporting to a NestJS app on the Express or Fastify platform. Read the backend overview first for how context and trace correlation work.

You need an app token. Create a JavaScript application in Bugsee and choose NestJS as its target; see Create your app.

Install​

npm install @bugsee/nestjs

Peer dependencies: @nestjs/common and @nestjs/core (version 9, 10, 11 or 12) and rxjs 7. Node.js 18 or newer, and Node.js 20 or newer for Nest 12 itself.

Set up​

Call launch() at the top of your server entry, then pass the Nest application to setupNest:

main.ts
import { launch, setupNest } from '@bugsee/nestjs';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

launch('<your_app_token>');

async function bootstrap() {
const app = await NestFactory.create(AppModule);
setupNest(app);
await app.listen(3000);
}

void bootstrap();

launch() returns the client directly on Node.js, so it needs no await. The bootstrap function keeps the example valid in a CommonJS project, where top-level await is not available.

What it does​

setupNest installs two things:

  • A context middleware that opens a request context for each request.
  • By default, a global interceptor that starts an http.server transaction, continues an inbound traceparent, and reports a thrown error before re-throwing it untouched. Nest's own exception filters still format the response.

A Nest HttpException is deliberate control flow and is not reported, whatever its status. Any other thrown error is reported.

Choose where errors are caught​

The errorCapture option picks the seam that catches errors.

errorCaptureCatchesNotes
'interceptor' (default)Route handlers, services and pipesReports and re-throws. Never conflicts with your own filter. Does not see errors thrown in guards.
'filter'Also guardsInstalls a global ExceptionFilter. Being a catch-all, it can collide with your own global filter.
'both'Everything aboveInterceptor and filter together. An error is reported once.
setupNest(app, { errorCapture: 'both' });

If you already have a global exception filter, keep the default or decorate your filter's catch method with BugseeExceptionCaptured instead of using 'filter' or 'both':

import { BugseeExceptionCaptured } from '@bugsee/nestjs';

@Catch()
export class MyFilter extends BaseExceptionFilter {
@BugseeExceptionCaptured()
catch(exception: unknown, host: ArgumentsHost) {
// your handling
}
}

Options​

Pass options as the second argument of setupNest.

OptionTypeDefaultDescription
errorCapture'interceptor' | 'filter' | 'both''interceptor'Where errors are caught. See above.
user(req) => string | undefinedoffThe end-user identity for reports raised during the request.
shouldReport(error) => booleanskips HttpExceptionDecides whether a thrown error is reported.
onError(error) => voidnoneReceives a failure of the adapter itself. It never reaches the request.

req is a structural view of the request of your Nest platform (Express or Fastify): method, url, originalUrl, route, routeOptions and headers.

Launch options​

The adapter does not change the launch options. These are the ones that matter most on a server:

OptionDefaultDescription
instrumentIncomingRequeststrueAutomatic per-request context and http.server transaction. See the backend overview.
captureLocalVariablesfalseAttach local variables to the stack frames of a reported error. See Diagnostics.
captureSourceContextfalseAttach the source lines around each stack frame. See Diagnostics.
detectHangstrueReport event-loop hangs. See Hangs.
profilingfalseAttach a rolling CPU profile to reports. See Diagnostics.

@bugsee/nestjs installs @bugsee/bugsee for you and re-exports everything from its Node entry, so launch and the SDK types come from this one package. You do not install or import @bugsee/bugsee separately. On Bun, see Running on Bun.

Found an issue, typo, or wrong statement on this page? Report it now →