Documentation
NestJS
Use @telemetry-tracker/node in NestJS backends. Call init() in main.ts before NestFactory.create so global uncaughtException and unhandledRejection handlers are installed, then register TelemetryInterceptor so exceptions thrown in controllers are reported. Optional Nest middleware tracks HTTP requests. For plain Express or Fastify without Nest, see the Node.js guide.
Install
pnpm add @telemetry-tracker/node
# or
npm install @telemetry-tracker/nodeInitialize in main.ts
Call init() as early as possible — before creating the Nest application:
import { NestFactory } from "@nestjs/core";
import { init, TelemetryInterceptor } from "@telemetry-tracker/node";
import { AppModule } from "./app.module";
async function bootstrap() {
init({
ingestUrl: process.env.TELEMETRY_INGEST_URL ?? "https://your-api.example.com",
app: process.env.TELEMETRY_APP ?? "my-nest-api",
apiKey: process.env.TELEMETRY_API_KEY,
platform: "node",
environment: process.env.NODE_ENV,
});
const app = await NestFactory.create(AppModule);
// Report controller/provider exceptions (Nest catches them before Node's global handlers).
app.useGlobalInterceptors(new TelemetryInterceptor());
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();Controller exceptions
Nest catches exceptions from controllers and the services they call and turns them into HTTP responses, so they never reach the process handlers. The global TelemetryInterceptor (node 1.5.0+) reports them with the method, path (no query string) and handler name, then rethrows the original error, so Nest's response and your exception filters are unchanged. HTTP exceptions below 500 (for example NotFoundException) are not reported; pass { shouldReport: (err) => boolean } to change that. Errors thrown in guards or middleware run before interceptors: report those from your own exception filter with captureNestException(exception, host).
// optional: custom global filter that also reports
import { ArgumentsHost, Catch } from "@nestjs/common";
import { BaseExceptionFilter } from "@nestjs/core";
import { captureNestException } from "@telemetry-tracker/node";
@Catch()
export class ReportingFilter extends BaseExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
captureNestException(exception, host);
super.catch(exception, host);
}
}
// main.ts: const { httpAdapter } = app.get(HttpAdapterHost);
// app.useGlobalFilters(new ReportingFilter(httpAdapter));
// Use either the filter or the interceptor for controller errors, not both.Request middleware
Wrap the generic middleware() from @telemetry-tracker/node in a Nest middleware class to emit $request events (method, url, duration). The url is the full request URL (req.originalUrl, node 1.5.0+); older versions recorded / inside Nest middleware:
// telemetry.middleware.ts
import { Injectable, NestMiddleware } from "@nestjs/common";
import type { NextFunction, Request, Response } from "express";
import { middleware } from "@telemetry-tracker/node";
const trackRequest = middleware({ trackRequestBody: false });
@Injectable()
export class TelemetryMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: NextFunction) {
trackRequest(req, res, next);
}
}// app.module.ts
import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common";
import { TelemetryMiddleware } from "./telemetry.middleware";
@Module({ /* imports, controllers, providers */ })
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(TelemetryMiddleware).forRoutes("*");
}
}Handled errors
Global process handlers and TelemetryInterceptor cover uncaught failures. For errors you catch yourself, call trackError to add context:
import { trackError } from "@telemetry-tracker/node";
try {
await this.ordersService.charge(id);
} catch (err) {
trackError(err, { orderId: id, handler: "OrdersController.charge" });
throw err;
}Per-request user context
After authentication, call identify(userId) in a guard or interceptor so errors and events include the current user:
import { identify } from "@telemetry-tracker/node";
// e.g. in an AuthGuard or interceptor after validating JWT
identify(req.user.id);