🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@byndyusoft/nest-opentracing

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@byndyusoft/nest-opentracing

Nest.js implementation of opentracing

latest
Source
npmnpm
Version
2.6.0
Version published
Maintainers
4
Created
Source

nest-opentracing

Implementation of Distributed Tracing for Nest.js modules.

So far only the express framework is supported.

Usage

Installing

npm i @byndyusoft/nest-opentracing @nestjs/axios @nestjs/common axios express

Initialization

Import tracing module in your root module just once.

Jaeger tracer

import { JaegerTracingModule } from "@byndyusoft/nest-opentracing";

@Module({
  imports: [JaegerTracingModule.forRoot({ applyRoutes: ["v1/*"], ignoreRoutes: [] })],
  controllers: [AppController],
})
export class AppModule {}

Custom tracer

import { OpenTracingModule } from "@byndyusoft/nest-opentracing";

@Module({
  imports: [
    OpenTracingModule.forRootAsync({
      useFactory: () => ({
        tracer: initSomeTracer(),
        applyRoutes: ["v1/*"],
        ignoreRoutes: [],
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

Log request/response bodies

import { OpenTracingModule } from "@byndyusoft/nest-opentracing";

@Module({
  imports: [
    OpenTracingModule.forRootAsync({
      useFactory: () => ({
        applyRoutes: ["v1/*"],
        ignoreRoutes: [],
        logBodies: true,
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

Tracing Nest.js HttpModule

import { JaegerTracingModule, TracedHttpModule } from "@byndyusoft/nest-opentracing";

@Module({
  imports: [
    JaegerTracingModule.forRoot({ applyRoutes: [AppController], ignoreRoutes: [], logBodies: true }),
    TracedHttpModule.registerAsync({
      useFactory: () => ({
        logBodies: true,
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

Configuration

Jaeger tracer

Configures by Jaeger environment variables and next variables:

npm_package_version
NAMESPACE
NODE_ENV

Traced HTTP module

TracedHttpModule can be configured via registerAsync pattern.

import { JaegerTracingModule, TracedHttpModule } from "@byndyusoft/nest-opentracing";

@Module({
  imports: [
    TracedHttpModule.registerAsync({
      useFactory: () => ({
        logBodies: true,
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

Async functions tracing

import { TracingService } from "@byndyusoft/nest-opentracing";

@Controller()
class AppController {
  constructor(private readonly tracingService: TracingService) {}

  @Get("foo")
  async bar() {
    /* some code here */

    const asyncResult = await this.tracingService.traceAsyncFunction(
      "description",
      async () => await someAsyncAction("foo", "bar"),
    );

    /* some code here */
  }
}

Keywords

byndyusoft

FAQs

Package last updated on 24 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts