inspector.restDocs

Behavior under load and quota

How the Node.js SDK protects your application under load and what it does when ingest is slow, unreachable, full or over quota - queue bounds, load shedding order, retries and the monthly request limit.

The SDK is built to slow your application down as little as possible, and to never break a request. Its main measure is speed and a small footprint, and it is measured by a benchmark on every change.

The request path

  • Only references. On the request path the SDK stores references. There is no copying, no JSON.stringify and no encoding. Sizes are estimated with string.length. Labels are resolved once per request.
  • One record per request. Request, response, body, retries, errors and the final outcome are merged in memory and sent as one record. A request that is still running after 2 seconds is sent as an “in progress” record, which the finished record replaces.
  • Serialization and compression are off the request path. By default they run on a worker thread; the main thread only copies finished records, in slices of about a millisecond. Without a worker thread, serialization runs in short slices that yield to the event loop and compression runs in the libuv thread pool.
  • Sending. fetch with keep-alive, up to max_in_flight batches at once, a batch per 1 MiB or per second.
  • Failures never reach your requests. Errors inside the SDK are swallowed.

Bounded memory

Everything the SDK holds is bounded by max_queue_bytes (64 MiB by default). When the bound is hit the oldest records are dropped. The number is reported in the next batch (dropped.records) and shown in the app.

Load budget

When serialization would use more than max_cpu_share of the application thread (default 10%), more than max_bytes_per_second would be sent (default 20 MiB), or the queue fills up, the SDK sheds work in this order:

  1. binary bodies,
  2. text bodies,
  3. whole records.

Whole records are shed only for CPU or bandwidth pressure; a full queue drops its oldest records. A shed body is replaced by a descriptor with omitted: 'load'. The app shows the counts as “N bodies skipped because of load”. You always see that a request happened, even when its body was dropped.

What the SDK does when ingest answers

Ingest answersThe SDK
2xxDone. Records listed under rejected are counted in stats().rejected_records.
413Splits the batch in halves and sends them again, and lowers the batch size. A single record that is still too large is dropped and counted.
415Switches from zstd to gzip.
429 with quota_exceededThe monthly request limit is reached. See below.
403 with organization_suspendedPauses like on quota_exceeded.
other 429, 408, 5xx (including 503 with Retry-After), network errors, timeoutsKeeps the batch and retries with exponential backoff, honoring Retry-After, within the queue bound. After failure_threshold failures in a row the circuit stays open for circuit_open_ms.
401The key is invalid or revoked. The SDK disables itself and warns once.
other 4xxThe batch cannot be fixed by retrying. It is dropped, counted and reported once.

When the storage server is almost out of disk space it answers 503 with Retry-After. The SDK does not throw data away; it waits within the queue bound.

When the monthly request limit is reached

When your organization reaches the recorded-request limit of its plan, ingest answers 429 with the code quota_exceeded and Retry-After: 60.

  1. The SDK stops capturing: no records are kept and nothing is serialized, so the cost for your application drops to almost nothing.
  2. About once a minute it sends an empty batch to find out whether recording is possible again.
  3. When you upgrade your plan or the period resets, the probe succeeds and capturing resumes, at the latest about a minute later.

Your requests are never affected. The app shows a “Not recording” indicator and a banner with the time recording stopped. Owners and admins also receive an email at 80% and at 100% of the limit.

Benchmark

The Node.js SDK repository contains a benchmark that compares an axios client with and without the SDK: requests per second, p99 latency, main-thread CPU, the longest event loop block, memory and record loss. It runs in CI and fails when a limit is exceeded.