NestJS Profiler

nest-profiler-mikro-orm

MikroORM query collector for @eleven-labs/nest-profiler.

@eleven-labs/nest-profiler-mikro-orm

@eleven-labs/nest-profiler-mikro-orm captures every SQL query executed by MikroORM during a profiled execution and displays them in a dedicated Database panel.

Database panel — MikroORM SQL queries with type badge, duration bar and slow-query highlighting

Installation

pnpm add @eleven-labs/nest-profiler-mikro-orm

Peer dependencies: @mikro-orm/core ^7.0.0, @mikro-orm/nestjs ^7.0.0

Setup

Register MikroOrmCollectorModule after MikroOrmModule in your root module. No extra MikroORM configuration is required — the collector wraps the ORM logger automatically:

app.module.ts
import { Module } from '@nestjs/common';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';
import { MikroOrmCollectorModule } from '@eleven-labs/nest-profiler-mikro-orm';

@Module({
  imports: [
    MikroOrmModule.forRoot({
      driver: PostgreSqlDriver,
      // ...your connection options
    }),
    MikroOrmCollectorModule.forRoot({
      slowQueryThreshold: 100, // ms — queries above this are highlighted (default: 100)
    }),
  ],
})
export class AppModule {}

What it collects

For each SQL query executed during a request:

FieldDescription
sqlThe SQL query string (with keyword highlighting)
parametersBound parameters
durationExecution time in ms (from MikroORM's took)
typeSELECT, INSERT, UPDATE, DELETE, OTHER
isSlowtrue if duration ≥ slowQueryThreshold
startedAtUnix timestamp
errorSet when MikroORM reports the query at error level

Slow queries are highlighted in red in the panel.

Toolbar badge

The toolbar badge shows: {n}q (e.g., 5q). When slow queries are present: 5q (2 slow).

How it works

The collector wraps MikroORM's Logger.logQuery at module initialization (OnModuleInit). MikroORM's SQL connection always measures execution time and calls logQuery with the query, its parameters and the elapsed took; the collector pushes a query entry into the active request profile (resolved via nestjs-cls) and lets the original logger handle console output only if you had query logging enabled. Queries executed outside a request context (startup, background jobs) are silently ignored.

This captures all queries issued through the EntityManager, repositories and the QueryBuilder.


Part of the nest-profiler toolkit · Powered & maintained by Eleven Labs

Powered & maintained by

On this page