NestJS
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
- pnpm
- yarn
- bun
npm install @bugsee/nestjs
pnpm add @bugsee/nestjs
yarn add @bugsee/nestjs
bun add @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:
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.servertransaction, continues an inboundtraceparent, 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.
errorCapture | Catches | Notes |
|---|---|---|
'interceptor' (default) | Route handlers, services and pipes | Reports and re-throws. Never conflicts with your own filter. Does not see errors thrown in guards. |
'filter' | Also guards | Installs a global ExceptionFilter. Being a catch-all, it can collide with your own global filter. |
'both' | Everything above | Interceptor 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.
| Option | Type | Default | Description |
|---|---|---|---|
errorCapture | 'interceptor' | 'filter' | 'both' | 'interceptor' | Where errors are caught. See above. |
user | (req) => string | undefined | off | The end-user identity for reports raised during the request. |
shouldReport | (error) => boolean | skips HttpException | Decides whether a thrown error is reported. |
onError | (error) => void | none | Receives 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:
| Option | Default | Description |
|---|---|---|
instrumentIncomingRequests | true | Automatic per-request context and http.server transaction. See the backend overview. |
captureLocalVariables | false | Attach local variables to the stack frames of a reported error. See Diagnostics. |
captureSourceContext | false | Attach the source lines around each stack frame. See Diagnostics. |
detectHangs | true | Report event-loop hangs. See Hangs. |
profiling | false | Attach 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.
Related pages
- Backend overview — request context, trace correlation and incoming-request instrumentation
- Issue detection — what else is detected on a server
- Performance — transactions and spans