Skip to content

e3m-software/nest-opentelemetry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Opentelemetry NestJS

OpenTelemetry NestJS is a module that provides instrumentation for NestJS applications.

Installation

npm install @e3m-software/nest-opentelemetry

Usage

// app.module.ts
@Module({
  imports: [OpentelemetryModule],
  controllers: [],
  providers: [],
})
export class AppModule {}

// Optional can be skipped ( But for controller you need to use CustomSpanRouter )
@Controller("v1/auth/admin")
export class AuthAdminController {
  constructor(private orchestrator: AuthOrchestrator) {}
  @Post()
  @Public(true)
  @CustomSpanRouter({ name: "WHATEVER_YOU_WANT_SPAN_NAME" })
  async login(@Body() body: DTO, @SpanRouter() span: unknown) {
    // Your Code
  }
}

// Outside of The Controller
@Injectable()
export class AuthOrchestrator {
  @CustomSpanMethod({ name: "WHATEVER_YOU_WANT_SPAN_NAME" })
  async loginCustomer(data): Promise<any> {
    // Your Code
  }
}

// What about using inside function....
// Simply use this CustomSpanWrapper()
@Injectable()
export class AuthOrchestrator {
  @CustomSpanMethod({ name: "WHATEVER_YOU_WANT_SPAN_NAME" })
  async loginCustomer(data): Promise<any> {
    // You can use this
    await CustomSpanWrapper(
      { name: "WHATEVER_YOU_WANT_SPAN_NAME" },
      async () => {
        // Your Code
      }
    );
  }
}

About

NestJS Opentelemetry Wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published