inspector.restDocs

Node.js SDK

Install @inspector-rest/sdk, create an inspector with your ingest key, instrument axios and shut down cleanly. Requires Node.js 22 or newer, no runtime dependencies.

@inspector-rest/sdk records the HTTP requests your Node.js application makes (request, response, bodies, retries, errors, timings) and ships them to your inspector.rest environment.

  • Zero runtime dependencies, TypeScript types included, Node.js 22 or newer.
  • Adapters for axios and the @sqaft-reverse/client observer. Any other HTTP client can report through lifecycle events.
  • One record per request, with all of its attempts.
  • zstd compression (gzip fallback), HTTP keep-alive, several batches in flight.
  • Works on Cloudflare Workers and other runtimes without Node built-ins.

Install

Terminal
npm install @inspector-rest/sdk

axios is an optional peer dependency (version 1.7 or newer). Install it if you use the axios adapter.

Quick start

JavaScript
import axios from 'axios';
import { create_inspector } from '@inspector-rest/sdk';
import instrument_axios from '@inspector-rest/sdk/axios';

const inspector = create_inspector({
  server_key: process.env.INSPECTOR_REST_KEY, // irk_<org-slug>_<secret>
  service: 'billing',
  labels: { env: 'production' },
});

instrument_axios(axios, inspector);

await axios.get('https://api.example.com/items');

// On shutdown (optional; the SDK also flushes on beforeExit and on SIGTERM / SIGINT):
await inspector.close();

CommonJS works the same way: const { create_inspector } = require('@inspector-rest/sdk') and const instrument_axios = require('@inspector-rest/sdk/axios').

The ingest key

Every environment has its own ingest key, shown once when you create it in the console. It has the form irk_<org-slug>_<secret>. The SDK derives the API address from it: https://<org-slug>.api.inspector.rest. Requests are recorded into the environment the key belongs to.

Without a usable server_key the SDK warns once and does nothing. Your requests are never affected. If the key is revoked, ingest answers 401; the SDK then disables itself and warns once.

Shutdown

The SDK flushes automatically on beforeExit and on SIGTERM / SIGINT (the signal is re-raised afterwards unless your application has its own handler). If you manage shutdown yourself, call await inspector.close(): it makes a final delivery attempt, including batches in flight and requests that are still running (they are reported as in progress), and then stops the inspector. It never waits longer than close_timeout_ms.

await inspector.flush() sends everything queued so far without stopping the inspector. It never rejects.

Diagnostics

inspector.stats() returns counters for diagnostics: the state, captured, sent and dropped records, held bytes, the load-shedding level and max_block_ms, the longest synchronous stretch the SDK ran on your application thread.

Next