NestJS Profiler
API Reference

nest-profiler-event-emitter

Types and API of the event emitter collector.

EventEntry

One entry per emit / emitAsync call made during a profiled execution — the rows of the Events panel.

Prop

Type

Entries implement the core TaggableEntry shape (duration, fingerprint, tags, error), so the performance-rule engine tags them under the event domain.

EventEmitterCollectorModuleOptions

Prop

Type

EventEntrypointData

Profile.entrypoint.data for a profile whose entrypoint is one @OnEvent handler execution (entrypoint.type === 'event').

Prop

Type

DiscoveredListener

One @OnEvent subscription found in the DI container, as returned by scanEventListeners.

Prop

Type

buildEventEntrypointType

function buildEventEntrypointType(error?: ProfilerErrorOptions): ProfilerEntrypointType;

Builds the event entrypoint type with a host-supplied error classification. A handler execution synthesises a 500 response when it throws, but the status layer is off by default for this kind — the verdict rests on the captured exception, so error: { exceptions: ['TimeoutError'] } narrows it to the failures that matter when a handler throws routinely as flow control. EVENT_ENTRYPOINT_TYPE_DEF is the same type with the default classification.

EventProfilerService registers the configured type at bootstrap; you never call this yourself unless you are building a variant.

Public exports

import {
  EventEmitterCollectorModule,
  EventEmitterCollector,
  EventEmitterPatch,
  EventProfilerService,
  EventDiscoverSource,
  EVENT_EMITTER_EVENTS_KEY,
  EVENT_ENTRYPOINT_TYPE,
  EVENT_ENTRYPOINT_TYPE_DEF,
  EVENT_ICON,
  buildEventEntrypointType,
  scanEventListeners,
} from '@eleven-labs/nest-profiler-event-emitter';

import type {
  EventEmitterCollectorModuleOptions,
  EventEmitterCollectorModuleAsyncOptions,
  EventEntry,
  EventEntrypointData,
  DiscoveredListener,
} from '@eleven-labs/nest-profiler-event-emitter';

Setup

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

@Module({
  imports: [
    ProfilerModule.forRoot({ isGlobal: true }),
    EventEmitterCollectorModule.forRoot({ ignoreEvents: [/^internal\./] }),
  ],
})
export class ProfilingModule {}

ProfilingModule is the dev-only bundle loaded by main-dev.ts — see Enabling and disabling the profiler. If the profiler is installed as a production dependency behind the runtime gate, wrap the same call in ConditionalModule.registerWhen(..., isProfilerEnabled).

EventEmitterModule.forRoot() stays in your own application module; the collector resolves EventEmitter2 and discovers the @OnEvent handlers across the application.

forRootAsync resolves the option values from DI (thresholds from ConfigService, for instance); enabled stays a synchronous build-time decision, so behind the runtime gate wrap it in ConditionalModule.registerWhen(...).

EventEmitterCollectorModule.forRootAsync({
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({
    slowThreshold: config.get<number>('profiler.performance.slowThreshold'),
    capturePayload: config.get<boolean>('profiler.capturePayload'),
  }),
});

Prerequisite: EventEmitterModule.forRoot() from @nestjs/event-emitter must be registered (it provides EventEmitter2 globally). Pass emitterToken when the emitter is bound to a custom token.

Powered & maintained by

On this page