NestJS Integration Guide
Backtrace captures and reports handled and unhandled exceptions in your production software so you can manage application quality through the complete product lifecycle.
The @backtrace/nestjs SDK connects your JavaScript application to Backtrace. The basic integration is quick and easy, after which you can explore the rich set of Backtrace features.
Table of Contents
Basic Integration
Install the package
$ npm install @backtrace/nestjs
Integrate the SDK
Add the following code to your application before all other scripts to report NestJS errors to Backtrace.
// Import the BacktraceClient from @backtrace/nestjs
import { BacktraceClient, BacktraceConfiguration, BacktraceModule } from '@backtrace/nestjs';
// Configure client options
const options: BacktraceConfiguration = {
// Submission url
// <universe> is the subdomain of your Backtrace instance (<universe>.backtrace.io)
// <token> can be found in Project Settings/Submission tokens
url: 'https://submit.backtrace.io/<universe>/<token>/json',
};
// Initialize the client with the options
BacktraceClient.initialize(options);
// By default, Backtrace will send an error for Uncaught Exceptions and Unhandled Promise Rejections
// For capturing NestJS errors, see "Add a Backtrace error interceptor" in this README
// Register BacktraceModule in your base module
@Module({
imports: [BacktraceModule],
controllers: [AppController],
})
class AppModule {}
@Controller()
class AppController {
// Inject BacktraceClient into your services or controllers
constructor(private readonly _client: BacktraceClient) {}
@Post()
public endpoint() {
// Manually send an error
this._cclient.send(new Error('Something broke!'));
}
}
Upload source maps
Client-side error reports are based on minified code. Upload source maps and source code to resolve minified code to your original source identifiers.
(Source Map feature documentation)