reverse-client and lifecycle events
Use the @sqaft-reverse/client observer adapter, or report requests from any HTTP client with the SDK's lifecycle events on_request, on_response, on_body, on_retry, on_error and on_settled.
@sqaft-reverse/client
import { create_client } from '@sqaft-reverse/client';
import create_reverse_client_observer from '@inspector-rest/sdk/reverse-client';
const client = create_client({ observer: create_reverse_client_observer(inspector) });The observer forwards the engine’s six lifecycle events to the inspector, including every retry decision. The lifetime of the inspector (flush and close) belongs to you; client.dispose() does not close it.
Lifecycle events
Any HTTP client can report through the inspector’s on_* methods. They are synchronous, never throw and only keep references. The events of one request are matched by request_id and merged into one record.
| Method | Payload fields |
|---|---|
on_request | request_id, labels?, attempt? (default 1), method, url, headers?, proxy_url?, body? |
on_response | request_id, labels?, attempt?, status, headers?, duration_ms? |
on_body | request_id, labels?, attempt?, bytes?, parse_ok?, read_ms?, raw_body? |
on_retry | request_id, labels?, attempt?, policy?, stage?, delay_ms?, exhausted? |
on_error | request_id, labels?, attempt? (omit for a request-level error), phase?, error |
on_settled | request_id, labels?, method?, url?, attempts?, outcome ('ok' or 'error'), duration_ms?, error? |
Bodies are strings, Uint8Array, Buffer, ArrayBuffer, URLSearchParams or plain objects. Headers are plain objects, Headers or axios header objects.
A request-level error (attempt omitted, or phase: 'domain') is kept even when it arrives shortly after on_settled, and it makes the outcome error.
Example: a custom client
import { randomUUID } from 'node:crypto';
async function tracked_fetch(url, init = {}) {
const request_id = randomUUID();
const started = performance.now();
inspector.on_request({ request_id, method: init.method ?? 'GET', url, headers: init.headers, body: init.body });
try {
const response = await fetch(url, init);
inspector.on_response({ request_id, status: response.status, headers: response.headers, duration_ms: performance.now() - started });
inspector.on_settled({ request_id, outcome: response.ok ? 'ok' : 'error', duration_ms: performance.now() - started });
return response;
} catch (error) {
inspector.on_error({ request_id, phase: 'network', error });
inspector.on_settled({ request_id, outcome: 'error', duration_ms: performance.now() - started, error });
throw error;
}
}Reading the response body for on_body is up to your client; pass raw_body when you have it.