DEV Community

Anuwong Mongkudkornburee
Anuwong Mongkudkornburee

Posted on

NestJS Jaeger(and others) Tracing Module for microservices. You'll loved it! ❤️

Once my team have to track the application behavior after it had been deployed to production for a few months. We are looking for an easy way to add the tracing things on top of production-ready application. so we developed this package. nestjs-jaeger-tracing.

To use this module, you just import TracingModule to your AppModule and initiate with forRoot() to add app level interceptor to deserialize microservice payload. Then add serializer which will inject tracing id to payload, like this.

import { TracingModule } from '@dollarsign/nestjs-jaeger-tracing';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';

@Module({
  imports: [
    TracingModule.forRoot({
      exporterConfig: {
        serviceName: 'core-service', // service name that will be shown in jaeger dashboard
      },
      isSimpleSpanProcessor: true, // true for development.
    }),
    ClientsModule.register([
      {
        name: 'MATH_SERVICE',
        transport: Transport.TCP,
        options: {
          port: 3001,
          ...TracingModule.getParserOptions(), // this method will return serializer that inject tracing id to microservice payload.
        },
      },
    ]),
  ],
})
export class AppModule {}
Enter fullscreen mode Exit fullscreen mode

Now, your application will be sent data to jaeger agent so you can trace your application in Jaeger Dashboard. hurayyyy!

It has so much work to do more, so feel free to use and contribute for your works.

Top comments (2)

Collapse
 
dealwap profile image
Abdulrasaq Nasirudeen

Thank you for making such a great library, I have a question, should this be integrated inside of the API Gateway or it needs to be set up within each micro services?

Collapse
 
billionaire9 profile image
Anuwong Mongkudkornburee

In current version, it should inject to each microservice you want to trace it, and should start with API Gateway (RESTful, Graphql)