ErrTapDocs

NestJS SDK

Install @errtap/nestjs to report unhandled exceptions from a NestJS app through a global exception filter, plus manual capture, logs and feedback.

Install

npm i @errtap/nestjs

@errtap/nestjs wraps @errtap/node and registers a global exception filter that reports unhandled exceptions, then lets Nest's normal error handling continue.

Initialise

// app.module.ts
import { Module } from '@nestjs/common';
import { ErrTapModule } from '@errtap/nestjs';

@Module({
  imports: [
    ErrTapModule.forRoot({
      dsn: process.env.ERRTAP_DSN!, // https://et_…@host
      environment: process.env.NODE_ENV,
      release: process.env.GIT_SHA,
    }),
  ],
})
export class AppModule {}

forRoot is global, so import it once in the root module. It initializes @errtap/node and registers ErrTapExceptionFilter as an APP_FILTER:

  • HttpExceptions with a status below 500 (validation errors, NotFoundException, …) are not reported.
  • 5xx HttpExceptions and every other thrown value are reported, then Nest's BaseExceptionFilter renders the usual response.

The Node SDK also reports uncaught exceptions and unhandled rejections outside requests. exitOnFatal keeps its Node default of true: Nest registers no crash handler of its own, so after an uncaught exception the process exits and restarts as it would without the SDK. Set exitOnFatal: false if you manage that differently.

If you already have your own global exception filter, build it on ErrTapExceptionFilter so exceptions are still reported:

import { ErrTapExceptionFilter } from '@errtap/nestjs';

export class AppExceptionFilter extends ErrTapExceptionFilter {}

Manual capture & logs

Everything from @errtap/node is re-exported:

import { captureException, captureMessage, logger } from '@errtap/nestjs';

logger.info('job started', { jobId });

try {
  await work();
} catch (e) {
  await captureException(e as Error, { context: { jobId } });
  throw e;
}

captureFeedback and lastEventId are re-exported too; see User feedback.

Options

FieldTypeDescription
dsnstringURL DSN (https://et_…@host) or bare key (requires endpoint)
endpointstringOverride ingest URL; optional when dsn is a URL DSN
environmentstringe.g. production, staging
releasestringTies errors to a deploy
tagsRecord<string, unknown>Attached to every event
exitOnFatalbooleanExit after reporting an uncaughtException. Default true