NestJS Profiler
Packagesnest-profiler

Overview

The core profiler module and its /_profiler web UI.

@eleven-labs/nest-profiler

@eleven-labs/nest-profiler provides execution profiling for NestJS applications. Each profiled execution receives a unique token, and the collected data (request, response, timing, CPU and memory, logs, exceptions, custom collectors) can be inspected at /_profiler/{token}. A Runtime view adds what the process itself is doing — memory, CPU, event-loop lag and garbage collection, sampled on an interval.

Profiler UI — profiles list with filters, HTTP statuses, durations and global panels

Installation

pnpm add -D @eleven-labs/nest-profiler nestjs-cls

nestjs-cls is a required peer dependency used for per-execution context propagation. Both are dev dependencies: the profiler is a development tool, loaded from a dev-only entrypoint, so production never installs it.

Keep them as regular dependencies only if your production code calls the profiler (a service injecting TracerService, the @Span() decorator…) — then gate it with ConditionalModule so it can be switched off in production.

Quick start

Bundle the profiler in its own module, and compose it with your application in a dev-only root module:

profiling/profiling.module.ts
import { Module } from '@nestjs/common';
import { ProfilerModule } from '@eleven-labs/nest-profiler';

@Module({ imports: [ProfilerModule.forRoot({ isGlobal: true, maxProfiles: 100 })] })
export class ProfilingModule {}
app.dev.module.ts
@Module({ imports: [AppModule, ProfilingModule] })
export class AppDevModule {}

A main-dev.ts boots AppDevModule with the profiler's logger, while main.ts keeps booting AppModule untouched:

main-dev.ts
import { ConsoleLogger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { createProfilerLogger } from '@eleven-labs/nest-profiler';
import { AppDevModule } from './app.dev.module';

async function bootstrap() {
  const app = await NestFactory.create(AppDevModule, { bufferLogs: true });
  app.useLogger(createProfilerLogger(new ConsoleLogger('App')));
  await app.listen(3000);
}
void bootstrap();

Run it with nest start --watch --entryFile main-dev, make a few requests, and open http://localhost:3000/_profiler. Every non-profiler response also carries an X-Debug-Token-Link header pointing straight to its profile. Enabling and disabling the profiler covers the shared bootstrap, the build configuration that keeps these files out of production, and the runtime gate for apps whose production code calls the profiler.

Documentation

Each capability has its own focused guide:

GuideWhat it covers
ConfigurationforRoot / forRootAsync, the full options reference, CPU and memory, securing the UI
Log captureWrapping any logger so every entry lands in the profile, supported argument conventions
Browsing profilesUI endpoints, debug headers, list filters (built-in and custom), exporting a profile
Trace & custom collectorsspan() timing, writing a collector with @ProfilerCollector(), custom EJS panels
Performance tagsThe rule engine behind slow, n-plus-one, chatty, large-payload and zero-rows, and custom rules
What counts as an errorDefining failure per entrypoint kind and per collector, and what the error tag and Errors filter keep
Extending the UI with JavaScriptCSP-friendly compiled bundles, the window.NestProfiler runtime, registering your own client script
Custom protocol adaptersProfiling gRPC, Kafka, WebSockets… via IContextAdapter
Storage backendsIn-memory (default), file system, the SQLite adapter, custom IProfilerStorageAdapter
Performance impact & testingDeferred persistence, why it is free, flush() in automated tests

The Getting started guide covers the full setup including the optional collector packages (TypeORM, MikroORM, Mongoose, Axios, cache, auth, config, validator, GraphQL, commander), and the Profiler UI page gives a visual tour of every panel.

Public API

import {
  ProfilerModule,
  ProfilerNoopModule,
  TracerService,
  TraceSpanDelegate,
  Span,
  createProfilerInstrument,
  ProfilerStorageService,
  CollectorRegistry,
  ProfilerCollector,
  HTTP_ICON,
  ClientAssetRegistry,
  PROFILER_STORAGE_ADAPTER,
  MemoryStorageAdapter,
  FileStorageAdapter,
  createProfilerLogger,
  parseLogArgs,
  DEFAULT_LOG_METHODS,
} from '@eleven-labs/nest-profiler';

import type {
  ProfilerModuleOptions,
  ProfilerModuleAsyncOptions,
  IProfilerCollector,
  IProfilerStorageAdapter,
  CollectorPanelInfo,
  GlobalPanelDescriptor,
  Profile,
  LogEntry,
  ExceptionEntry,
  TraceSpan,
  SecurityContext,
  LogMethodMap,
  LogArgsParser,
  ParsedLogCall,
  ProfilerLoggerOptions,
} from '@eleven-labs/nest-profiler';

The full generated reference lives at API reference — nest-profiler.

Powered & maintained by

On this page