Skip to main content

API Reference

Everything NestLens exports, with the examples that show how each piece is meant to be used.

The exhaustive listing — every interface, every field, every default, straight from the source — is generated on each build and lives in the pages below this one. This page does not repeat it.

:::info Where the types are NestLensConfig is the whole configuration surface, and everything it names has a page of its own. Start there when you want a field list; start here when you want an example.

This page used to carry hand-typed copies of those interfaces. They fell four config options, sixteen interfaces and the entire GraphQL watcher behind the code before anyone noticed, which is why they are gone. :::

Core Exports​

NestLensModule​

The main module to import in your NestJS application.

import { NestLensModule } from 'nestlens';

@Module({
imports: [
NestLensModule.forRoot({
enabled: true,
path: '/nestlens',
}),
],
})
export class AppModule {}

Every option: NestLensConfig.

Configuration at a glance​

OptionWhat it doesReference
enabledTurn NestLens off without removing itNestLensConfig
pathWhere the dashboard is mountedBasic configuration
trustProxyHonour X-Forwarded-Prefix behind a rewriting proxyNestLensConfig
samplingRecord a fraction of traffic instead of all of itSamplingConfig
serverServe the dashboard on a listener of its ownNetwork isolation
watchersWhich watchers run, and how each behavesWatchers overview
storageWhere entries are keptStorage
pruningHow long they are keptPruning
rateLimitLimit requests to the APIRate limiting
authorizationWho may reach the dashboardAccess control
securityData masking and input validationData masking
alertingPOST entries to a webhookAlerting
filter / filterBatchDecide what is worth recordingFiltering entries

Services​

CollectorService​

Collect custom entries programmatically:

import { CollectorService } from 'nestlens';

@Injectable()
export class MyService {
constructor(private collector: CollectorService) {}

async trackCustomEvent() {
// Buffered collection (batched for performance)
await this.collector.collect('event', {
name: 'custom-event',
payload: { data: 'value' },
listeners: [],
duration: 0,
});
}

async trackCriticalEvent() {
// Immediate collection (bypasses buffer)
await this.collector.collectImmediate('exception', {
name: 'CriticalError',
message: 'Something critical happened',
context: 'HTTP',
});
}

// Pause/resume collection
pauseCollection() {
this.collector.pause('maintenance');
}

resumeCollection() {
this.collector.resume();
}
}

The payload is typed by the entry type you name, so the compiler tells you what each one needs: Entry is the union, and EntryType lists the names.

Full signature: CollectorService.

NestLensLogger​

Custom logger that integrates with NestLens:

import { NestLensLogger } from 'nestlens';

@Injectable()
export class MyService {
private readonly logger = new NestLensLogger(MyService.name);

doSomething() {
this.logger.verbose('Detailed info');
this.logger.debug('Debug info');
this.logger.log('General info');
this.logger.warn('Warning message');
this.logger.error('Error occurred', error.stack);
}
}

Those five are the whole set — the levels Nest's own logger uses. There is no info; log is its equivalent.

StorageInterface​

Implement a storage backend of your own and register it under the STORAGE token:

import { StorageInterface, Entry, STORAGE } from 'nestlens';

@Injectable()
export class CustomStorage implements StorageInterface {
async initialize(): Promise<void> { /* ... */ }
async save(entry: Entry): Promise<Entry> { /* ... */ }
async saveBatch(entries: Entry[]): Promise<Entry[]> { /* ... */ }

// …and the rest of the interface. There are 28 methods in all; the compiler
// will name every one you have not written yet.
}

@Module({
providers: [
{
provide: STORAGE,
useClass: CustomStorage,
},
],
})
export class AppModule {}

The complete list, with signatures: StorageInterface. For a worked example, see Extending storage.

Injection Tokens​

Every token a watcher asks you to provide is exported from the package root:

import {
STORAGE,
NESTLENS_CONFIG,
NESTLENS_EVENT_EMITTER,
NESTLENS_REDIS_CLIENT,
NESTLENS_MODEL_SUBSCRIBER,
NESTLENS_NOTIFICATION_SERVICE,
NESTLENS_VIEW_ENGINE,
NESTLENS_MAILER_SERVICE,
NESTLENS_HTTP_CLIENT,
NESTLENS_COMMAND_BUS,
NESTLENS_GATE_SERVICE,
NESTLENS_BATCH_PROCESSOR,
NESTLENS_DUMP_SERVICE,
REQUEST_ID_HEADER, // 'x-nestlens-request-id'
} from 'nestlens';

Each watcher's page explains what to provide under its token. NESTLENS_CONFIG holds the resolved configuration and NESTLENS_API_PREFIX is the path segment the API sits behind; both are exported too. The generated reference lists every one under Variables.

Internal Constants​

Used internally, not exported:

ConstantValueDescription
BUFFER_SIZE100Entries buffered before automatic flush
FLUSH_INTERVAL1000Flush interval in milliseconds

Default Sensitive Headers​

Masked in captured data without any configuration:

  • authorization
  • cookie
  • set-cookie
  • x-api-key
  • x-auth-token
  • x-access-token
  • x-refresh-token
  • x-csrf-token
  • proxy-authorization

sensitiveHeaders adds to this list. To replace it instead, pass { replace: [...] } — see Data masking.

Full Documentation​