Got integrates with Node.js diagnostic channels for low-overhead observability. Events are only published when subscribers exist.
Emitted when a request is created.
{requestId: string, url: string, method: string}Emitted before the native HTTP request is sent.
{requestId: string, url: string, method: string, headers: Record<string, string | string[] | undefined>}Emitted when response headers are received.
{requestId: string, url: string, statusCode: number, headers: Record<string, string | string[] | undefined>, isFromCache: boolean}Emitted when the response completes.
{requestId: string, url: string, statusCode: number, bodySize?: number, timings?: Timings}Emitted when retrying a request.
{requestId: string, retryCount: number, error: RequestError, delay: number}Emitted when a request fails.
{requestId: string, url: string, error: RequestError, timings?: Timings}Emitted when following a redirect.
{requestId: string, fromUrl: string, toUrl: string, statusCode: number}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.
All message types are exported from the main package:
import type {
DiagnosticRequestCreate,
DiagnosticRequestStart,
DiagnosticResponseStart,
DiagnosticResponseEnd,
DiagnosticRequestRetry,
DiagnosticRequestError,
DiagnosticResponseRedirect,
} from 'got';