Improved NestJS Tracing with Recap.Dev

Arseny Yankovski

Arseny Yankovski

Lead Architect @ eMarketeer

We just released a new 1.9.0 version of the recap.dev JavaScript client which exports a new wrapNestJsModule function. Which when used like this:

import { NestFactory } from '@nestjs/core';
import { wrapNestJsModule } from '@recap.dev/client';
const app = await NestFactory.create(wrapNestJsModule(AppModule));

will record calls and their timings of the controllers and injectables in the NestJS module.

A recap.dev timeline with NestJS module wrapped

We decided to make it a function that wraps a module to allow you to trace your application to your liking.

Tracing individual functions allows for different unit naming strategies. One example is making the unit name a combination of an environment, controller name, and a controller method name. We can write a middleware to do that automatically.

app.use((req, res, next) => {
res.prependListener('finish', () => {
tracer.setUnitName(`${process.env.environment}-${tracer.getCurrentTrace()?.functionCallEvents[1]?.functionName}`);
});
next();
});

This will result in a unit name like this: local-AppController.getHello

Check the complete source code of an example NestJS project traced with recap.dev here

Adding recap.dev to your application won't take more than 5 minutes.

Click here to learn how to get started with recap.dev