NestJS Profiler

nest-profiler-http

HTTP client collector for @eleven-labs/nest-profiler — the ready-made axios adapter for the HTTP Client panel.

@eleven-labs/nest-profiler-http

@eleven-labs/nest-profiler-http captures outgoing HTTP requests and displays them in a dedicated HTTP Client panel. It is client-agnostic: it owns the HttpRequestEntry contract, the collector, the HttpProfilerRecorder and an HttpInstrumentation interface. An axios adapter is bundled and enabled by default; fetch, undici, got or any custom client can feed the same panel.

Renamed from @eleven-labs/nest-profiler-axios, which is now deprecated and re-exports this package (AxiosCollectorModule remains as an alias of HttpCollectorModule).

HTTP Client panel — outgoing requests with method, URL, status and duration

Installation

pnpm add @eleven-labs/nest-profiler-http
# for the bundled axios adapter (optional):
pnpm add @nestjs/axios axios

Optional peer dependencies: axios ^1.0.0, @nestjs/axios ^4.0.0 — only needed for the axios adapter.

Setup (axios, default)

Import HttpCollectorModule to register the panel. The axios adapter is on by default and patches the HttpService provided by @nestjs/axios's HttpModule in the same module:

app.module.ts
import { HttpModule } from '@nestjs/axios';
import { HttpCollectorModule } from '@eleven-labs/nest-profiler-http';

@Module({
  imports: [
    HttpModule, // provides HttpService — required for the axios adapter
    HttpCollectorModule.forRoot(),
    ProfilerModule.forRoot({ isGlobal: true }),
  ],
})
export class AppModule {}

Inject HttpService in your services as usual — requests are captured automatically.

Bring your own HTTP client

No axios? Inject HttpProfilerRecorder and call capture() from any client. capture() applies your capture options (request/response headers + body) and masks sensitive headers for you — so a custom client shows the same request/response detail in the panel as axios:

import { HttpProfilerRecorder } from '@eleven-labs/nest-profiler-http';

@Injectable()
export class WeatherService {
  constructor(private readonly http: HttpProfilerRecorder) {}

  async getForecast() {
    const url = 'https://api.weather.example.com/forecast';
    const requestHeaders = { accept: 'application/json' };

    const startedAt = Date.now();
    const res = await fetch(url, { headers: requestHeaders });
    const body = await res.json();

    this.http.capture({
      method: 'GET',
      url,
      startedAt,
      duration: Date.now() - startedAt,
      statusCode: res.status,
      requestHeaders,
      responseHeaders: res.headers, // fetch `Headers` (and `Map`) are supported
      responseBody: body,
    });

    return body;
  }
}

capture() honours the configured captureRequestHeaders / captureRequestBody / captureResponseHeaders / captureResponseBody flags and the maskHeaders list. Use record(entry) instead if you have already built a final HttpRequestEntry and want to bypass the options. A runnable version lives in the example API at GET /posts/via-fetch.

For a reusable integration, implement HttpInstrumentation (install(recorder)) and register it via HttpCollectorModule.forRoot({ instrumentations: [MyInstrumentation] }) — that is exactly how the bundled axios adapter works.

Options

HttpCollectorModule.forRoot(options) accepts:

OptionDefaultDescription
enabledtrueRegister the collector and instrumentations.
axiostrueEnable the bundled axios adapter (no-op without axios).
instrumentations[]Custom HttpInstrumentation providers to install.
captureRequestHeaderstrueCapture (and mask) outgoing request headers.
captureRequestBodytrueCapture request body for non-GET/HEAD requests.
captureResponseHeaderstrueCapture (and mask) response headers.
captureResponseBodyfalseCapture response body (can be large).
maskHeaders[]Extra header names to redact (merged with the defaults).

What it collects

For each outgoing request: method, url, statusCode, duration, startedAt, optional error, and (per options) request/response headers and bodies.

Toolbar badge

Request count (e.g. 3). When errors are present: 3 (1 err).


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

Powered & maintained by

On this page