TypeScript / NestJS

Instrument NestJS APIs.

Register one global interceptor for NestJS applications running on either Express or Fastify.

NestJS 10–11Package v0.2.0Production ready
01

Quickstart

Install the public npm packages.

The framework adapter uses @apirelio/core for the common event contract and bounded asynchronous transport.

Terminalbash
npm install @apirelio/nestjs @apirelio/core
02

Framework integration

Enable automatic request tracking.

The global interceptor supports both NestJS HTTP platforms, preserves the original exception and records the final response outcome.

app.module.tstypescript
import { Module } from '@nestjs/common'
import { ApirelioModule } from '@apirelio/nestjs'

@Module({
  imports: [
    ApirelioModule.forRoot({
      apiKey: process.env.APIRELIO_API_KEY ?? '',
      service: 'billing-api',
      environment: 'production',
      includeRoutes: ['/api/**'],
      excludeRoutes: ['/api/health', '/api/internal/**'],
      resolveCustomer: request => request.user ? {
        id: String(request.user.companyId),
        name: request.user.companyName,
      } : null,
    }),
  ],
})
export class AppModule {}
03

Customer context

Attach the account and application.

Use stable external IDs from your authentication model. Customer names and plans can evolve without breaking analytics history.

Async configurationtypescript
ApirelioModule.forRootAsync({
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({
    apiKey: config.getOrThrow('APIRELIO_API_KEY'),
    service: 'billing-api',
  }),
})
04

Reliability

Flush safely during shutdown.

Call app.enableShutdownHooks() so Nest lifecycle shutdown triggers the final queue flush.

includeRoutes accepts exact paths or prefixes ending in /**. Explicit excludeRoutes always take precedence, keeping health checks, internal endpoints and presentation routes out of API analytics.

Non-blocking capture

The request only appends to a bounded in-memory queue. Network delivery, retry and batching happen outside the observed response path.

05

Data boundary

Operational signals only.

Request and response bodies, authorization values, cookies, query values, email addresses and client IP addresses are not captured. Custom scalar metadata must be explicitly allow-listed.

Server credentials only

Keep the ingestion key in server environment configuration. Do not expose it through client bundles or public runtime config.