All Integrations
LanguagesGlobal Interceptor + @Span() Decorator

NestJS Integration

Monitor NestJS applications with decorator-based distributed tracing, guard and interceptor timing, microservice message traces, and module bootstrap performance. APM built for NestJS.

Setup

How It Works

01

Install the NestJS SDK

Run npm install @tigerops/nestjs. The package provides a NestJS module with a global interceptor, exception filter, and optional decorator for fine-grained span control — all idiomatic to the NestJS DI system.

02

Register the Global Interceptor

Import TigerOpsModule.forRoot() in your AppModule. It registers the global HTTP interceptor for all controllers, sets up the TracingInterceptor for distributed context propagation, and attaches the global exception filter.

03

Initialize in main.ts

Call TigerOps.init() before creating your NestJS application to capture early bootstrap metrics, module initialization time, and application startup health. Pass the app instance to finalize configuration.

04

Add Custom Spans

Use the @Span() decorator on any provider method to create named spans. Pass metadata as decorator arguments for richer context. TigerOps automatically propagates the active trace context without manual plumbing.

Capabilities

What You Get Out of the Box

Decorator-Based Tracing

Add @Span() to any controller, service, or repository method to create named distributed trace spans. Span metadata, custom attributes, and error capture work declaratively without modifying business logic.

Guard Execution Timing

Execution time for every NestJS guard (AuthGuard, RolesGuard, custom guards) per route. Identify slow authorization checks that are adding latency to your request pipeline.

Interceptor Chain Metrics

Per-interceptor execution duration for every interceptor in your global and route-level chains. Identify which interceptors are adding the most overhead to your request lifecycle.

Exception Filter Capture

All exceptions captured by NestJS exception filters are automatically forwarded to TigerOps with the request context, user identity, and active trace ID for immediate incident investigation.

Microservices & Event Patterns

TigerOps traces NestJS microservice message patterns (TCP, Redis, Kafka, NATS) and event emitter subscriptions, propagating trace context across service boundaries automatically.

Module Bootstrap Timing

Track NestJS module initialization order, provider instantiation time, and total application bootstrap duration. Identify slow module initialization that increases container cold start time.

Configuration

main.ts Interceptor Setup

Initialize TigerOps before bootstrapping your NestJS app and register the module for automatic distributed tracing.

src/main.ts
// src/main.ts — TigerOps NestJS setup
import { TigerOps } from '@tigerops/nestjs'

// Initialize BEFORE NestFactory.create() to capture bootstrap timing
TigerOps.init({
  apiKey: process.env.TIGEROPS_API_KEY!,
  service: 'my-nestjs-api',
  environment: process.env.NODE_ENV ?? 'production',
})

import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  // Pass app to TigerOps to finalize Express/Fastify adapter instrumentation
  TigerOps.instrument(app)
  await app.listen(3000)
}
bootstrap()

---
// src/app.module.ts — register TigerOpsModule globally
import { Module } from '@nestjs/common'
import { TigerOpsModule } from '@tigerops/nestjs'

@Module({
  imports: [
    TigerOpsModule.forRoot({
      // Global interceptor — traces all HTTP requests automatically
      enableGlobalInterceptor: true,
      // Global exception filter — captures all unhandled exceptions
      enableGlobalExceptionFilter: true,
      // Trace NestJS microservice message patterns
      enableMicroserviceTracing: true,
    }),
  ],
})
export class AppModule {}

---
// Using @Span() in a service
import { Injectable } from '@nestjs/common'
import { Span } from '@tigerops/nestjs'

@Injectable()
export class UserService {
  @Span('user.findById', { captureArgs: false })
  async findById(id: string) {
    // This method is automatically wrapped in a named trace span
    return this.userRepository.findOne({ where: { id } })
  }
}
FAQ

Common Questions

Does TigerOps support NestJS microservices with Kafka and Redis transports?

Yes. TigerOps instruments NestJS microservice transports including TCP, Redis, Kafka, NATS, RabbitMQ, and gRPC. Trace context is propagated through message headers on all supported transports, giving you distributed traces across your microservice mesh.

Does the @Span() decorator work with async methods and Observables?

Yes. The @Span() decorator supports async/await methods, Observable-returning methods (RxJS), and synchronous methods. For Observables, the span is closed when the Observable completes or errors, capturing the full async duration correctly.

Can TigerOps monitor NestJS WebSocket gateways?

Yes. TigerOps instruments NestJS WebSocket gateways to track connection lifecycle events, message handler execution time, and subscription errors. The @SubscribeMessage() handler timing and error capture work out of the box.

How does TigerOps integrate with NestJS CQRS module?

TigerOps auto-instruments the NestJS CQRS module command bus, query bus, and event bus. Command and query handler execution times are captured as spans, and events are correlated with the commands that triggered them.

Can I use TigerOps alongside Pino or Winston for structured logging?

Yes. TigerOps provides a NestJS logger adapter that wraps Pino or Winston and automatically injects the active trace ID and span ID into every log line. This makes it trivial to find the logs for a specific trace in TigerOps log search.

Get Started

Full Visibility Into Your NestJS Applications

No credit card required. Connect in minutes. Request traces, guard timing, and microservice spans immediately.