inspector.restDocs

Sampling, body rules and redaction

Control the volume and content of recorded requests with sample_rate, capture_body, max_body_bytes, host and path rules, header and field redaction and the redact_hook.

By default the SDK records every request completely, including full text bodies. These options reduce volume or remove sensitive data before anything leaves your process.

Sampling

JavaScript
create_inspector({ server_key, sample_rate: 0.1 }); // record 10% of requests

sample_rate is a fraction from 0 to 1. A request is either recorded completely (all attempts, bodies and errors) or not at all, so a sampled request is never half a record. Sampling is decided once per request.

Which hosts and paths

JavaScript
create_inspector({
  server_key,
  include_hosts: ['*.example.com', 'api.stripe.com'],
  exclude_paths: ['/health', '/metrics*'],
});
  • include_hosts / exclude_hosts take host patterns. * is a wildcard, matching is case-insensitive, and the port is ignored. With include_hosts, only matching hosts are recorded.
  • include_paths / exclude_paths take path patterns with the * wildcard. They are matched against the path without the query string.
  • Excluded requests are not recorded at all and cost nothing beyond the match.

Body rules

OptionEffect
capture_body: 'always' (default)Request and response bodies are captured.
capture_body: 'on_error'Bodies are kept only for failed requests. Successful requests are recorded without bodies.
capture_body: 'never'No bodies. Headers, status, timing and errors are still recorded.
max_body_bytesCuts text bodies at this many UTF-8 bytes, on a character boundary. The record keeps the original size and marks the body as truncated. There is no default limit.

Text bodies are captured completely unless you set max_body_bytes. Binary bodies follow their own rule: they are not captured unless you turn on capture_binary.

Redaction

Redaction is off by default: the data you send is the data you see. Turn it on for anything you do not want to store.

JavaScript
create_inspector({
  server_key,
  redact_headers: ['authorization', 'cookie', 'x-api-key'],
  redact_fields: ['password', 'card_number', 'access_token'],
});
  • redact_headers: header names (case-insensitive) whose values are replaced with [redacted].
  • redact_fields: field names that are redacted in JSON bodies, form bodies and URL query strings.
  • redact_hook: a function that receives the wire record before it is serialized. Mutate it, or return false to drop the record entirely.
JavaScript
create_inspector({
  server_key,
  redact_hook(record) {
    if (record.url.includes('/internal/')) return false; // do not record at all
    for (const attempt of record.attempts) {
      if (attempt.request?.body?.text) {
        attempt.request.body.text = attempt.request.body.text.replace(/\b\d{16}\b/g, '[card]');
      }
    }
  },
});

A redact_hook (like error_details and a custom fetch) runs on the application’s main thread, because functions cannot move to a worker thread. See Workers and other runtimes.

Redaction in the SDK removes data at the source. MCP masking is a second, independent layer that hides secrets from AI agents even when you chose to store them. See also Security and privacy.

Error details

JavaScript
create_inspector({ server_key, error_details: (error) => ({ code: error.code, upstream_id: error.upstreamId }) });

error_details adds the error’s own fields as details to the recorded error. A hook that throws is ignored.