NestJS Profiler
API Reference

nest-profiler-mikro-orm

Types and API of the MikroORM query collector.

MikroOrmCollectorModuleOptions

Options passed to MikroOrmCollectorModule.forRoot().

Prop

Type

QueryEntry

One entry per SQL query executed during a request. The SQL collector types are shared with the other SQL ORM collectors and re-exported from this package.

Prop

Type

QueryType

type QueryType = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'OTHER';

Detected from the first keyword of the SQL string.

Public exports

import { MikroOrmCollectorModule } from '@eleven-labs/nest-profiler-mikro-orm';
import { MikroOrmCollector } from '@eleven-labs/nest-profiler-mikro-orm';

import type {
  MikroOrmCollectorModuleOptions,
  MikroOrmCollectorModuleAsyncOptions,
  QueryEntry,
  QueryType,
} from '@eleven-labs/nest-profiler-mikro-orm';

Setup

// In any module that uses MikroORM:
MikroOrmCollectorModule.forRoot({
  slowThreshold: 50, // ms — queries at/above this are tagged 'slow'
});

Prerequisite: MikroOrmModule.forRoot() must be registered in the application (provides the MikroORM instance whose logger the collector wraps).

Async setup

Drive the options from ConfigService (or any provider) with forRootAsync(), gated per environment with ConditionalModule (recommended). It resolves option values only — for the enabled flag and when to prefer forRoot, see Enabling and disabling the profiler.

import { ConditionalModule, ConfigService } from '@nestjs/config';
import { MikroOrmCollectorModule } from '@eleven-labs/nest-profiler-mikro-orm';

const isProfilerEnabled = (env: NodeJS.ProcessEnv) => env['PROFILER_ENABLED'] !== 'false';

ConditionalModule.registerWhen(
  MikroOrmCollectorModule.forRootAsync({
    inject: [ConfigService],
    useFactory: (config: ConfigService) => ({
      slowThreshold: config.get<number>('PROFILER_SLOW_QUERY_MS') ?? 50,
    }),
  }),
  isProfilerEnabled,
);
Powered & maintained by

On this page