nest-profiler-rabbitmq
Types and API of the RabbitMQ message collector.
RabbitMqInfo
Payload of a message profile's entrypoint.data (entrypoint type: 'rabbitmq'). The module
registers a rabbitmq entrypoint type, so the profiler renders a dedicated RabbitMQ list table
- with its own filters: Delivery (first delivery / redelivered), Exchange and Handler
(both populated from the values actually captured) and a free-text Routing key - and a
Message detail tab, including the captured AMQP
headersandpayload. The HTTP-status filters do not appear here, since a consumed message has no HTTP response.
Prop
Type
Public exports
import { RabbitMqCollectorModule } from '@eleven-labs/nest-profiler-rabbitmq';
import { RabbitMqContextAdapter } from '@eleven-labs/nest-profiler-rabbitmq';
import { RABBITMQ_ENTRYPOINT_TYPE } from '@eleven-labs/nest-profiler-rabbitmq';
import type { RabbitMqCollectorModuleOptions } from '@eleven-labs/nest-profiler-rabbitmq';
import type { RabbitMqCollectorModuleAsyncOptions } from '@eleven-labs/nest-profiler-rabbitmq';
import type { RabbitMqInfo } from '@eleven-labs/nest-profiler-rabbitmq';RabbitMqCollectorModuleOptions
interface RabbitMqCollectorModuleOptions {
/** Capture incoming AMQP message headers (masked). Default: `true`. */
captureHeaders?: boolean;
/** Capture the deserialized message payload. Default: `true`. */
captureBody?: boolean;
/** Extra header names (lowercase) to mask, merged with the built-in list. */
maskHeaders?: string[];
/** What counts as a failed message. Default: the handler threw. */
error?: ProfilerErrorOptions;
}A consumed message carries no status code, so error rests on whether the handler threw — narrow it to the exceptions that matter, or take over with classify. See What counts as an error.
Gate the module per environment with ConditionalModule.registerWhen(RabbitMqCollectorModule.forRoot({ … }), isProfilerEnabled) — the same pattern used for every profiler module.
Setup
Register the module in the application that consumes your messages (the same process that hosts the profiler):
import { Module } from '@nestjs/common';
import { ConditionalModule } from '@nestjs/config';
import { RabbitMqCollectorModule } from '@eleven-labs/nest-profiler-rabbitmq';
const isProfilerEnabled = (env: NodeJS.ProcessEnv) => env['PROFILER_ENABLED'] === 'true';
@Module({
imports: [
ConditionalModule.registerWhen(RabbitMqCollectorModule.forRoot(), isProfilerEnabled),
// your RabbitMQModule with @RabbitSubscribe handlers
],
})
export class AppModule {}Drive the options from ConfigService (or any provider) with forRootAsync(), gated per environment with ConditionalModule (recommended) — it resolves option values only, not enabled (see Enabling and disabling the profiler):
import { ConditionalModule, ConfigService } from '@nestjs/config';
ConditionalModule.registerWhen(
RabbitMqCollectorModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
captureBody: config.get<boolean>('profiler.rabbitmqCaptureBody') ?? true,
maskHeaders: config.get<string[]>('profiler.maskHeaders') ?? [],
}),
}),
isProfilerEnabled,
);Wire the core ProfilerModule once at the root — see Enabling and disabling the profiler. If a service injects ProfilerService directly, also register its ProfilerNoopModule fallback.
@golevelup/nestjs-rabbitmq and amqplib are optional peer dependencies - the ones you already
install to consume messages. The module needs no changes to your @RabbitSubscribe handlers.
How a message profile is shaped
A consumed message has no HTTP request/response. The profiler synthesises a profile whose
entrypoint is { type: 'rabbitmq', data: RabbitMqInfo }:
| Field | Value |
|---|---|
entrypoint.type | rabbitmq |
entrypoint.data.exchange | The exchange (empty string for the default exchange) |
entrypoint.data.routingKey | The routing key |
entrypoint.data.headers | AMQP message headers, sensitive ones masked (when captureHeaders is enabled) |
entrypoint.data.payload | The deserialized payload (when captureBody is enabled) |
response.statusCode | 200 on success, 500 when the handler threw |
The exchange, routing key, handler, redelivered flag and AMQP consumer/delivery tags are kept on
entrypoint.data. Because the handler runs inside the profiler's CLS context, profile-scoped
collectors (HTTP client, database, …) capture the work it performs and contribute their own panels.