Skip to content

Latest commit

 

History

History
93 lines (61 loc) · 1.94 KB

File metadata and controls

93 lines (61 loc) · 1.94 KB

> Back to homepage

Diagnostics Channel

Got integrates with Node.js diagnostic channels for low-overhead observability. Events are only published when subscribers exist.

Channels

got:request:create

Emitted when a request is created.

{requestId: string, url: string, method: string}

got:request:start

Emitted before the native HTTP request is sent.

{requestId: string, url: string, method: string, headers: Record<string, string | string[] | undefined>}

got:response:start

Emitted when response headers are received.

{requestId: string, url: string, statusCode: number, headers: Record<string, string | string[] | undefined>, isFromCache: boolean}

got:response:end

Emitted when the response completes.

{requestId: string, url: string, statusCode: number, bodySize?: number, timings?: Timings}

got:request:retry

Emitted when retrying a request.

{requestId: string, retryCount: number, error: RequestError, delay: number}

got:request:error

Emitted when a request fails.

{requestId: string, url: string, error: RequestError, timings?: Timings}

got:response:redirect

Emitted when following a redirect.

{requestId: string, fromUrl: string, toUrl: string, statusCode: number}

Example

import diagnosticsChannel from 'node:diagnostics_channel';

const channel = diagnosticsChannel.channel('got:request:start');

channel.subscribe(message => {
	console.log(`${message.method} ${message.url}`);
});

All events for a single request share the same requestId.

TypeScript

All message types are exported from the main package:

import type {
	DiagnosticRequestCreate,
	DiagnosticRequestStart,
	DiagnosticResponseStart,
	DiagnosticResponseEnd,
	DiagnosticRequestRetry,
	DiagnosticRequestError,
	DiagnosticResponseRedirect,
} from 'got';