AccessLogSampler
Defined in: src/access-log.ts:228
Keep a deterministic fraction of access-log records.
Three properties separate a sampler that helps from one that quietly costs someone an incident, and all three are enforced here:
Errors are never sampled out. A rate below 1 exists because successful calls are repetitive, which is exactly what failures are not. A consumer must be able to read a fall in error count as a fix landing rather than as the dice going the other way.
The decision is per call, not per record. It is a function of a stable
identifier — stream_id when present, request_id otherwise — so every
record of one stream shares its init’s fate. Random per-record sampling
shreds a multi-record call into fragments indistinguishable from data loss,
and the calls likeliest to be split are the long streams worth studying.
The rate rides on each kept record as sample_rate. A consumer scaling
counts has to divide by it, and a rate discoverable only from a
deployment’s flags is a rate that gets guessed wrong.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AccessLogSampler(rate): AccessLogSampler;Defined in: src/access-log.ts:234
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
rate |
number |
Returns
Section titled “Returns”AccessLogSampler
Throws
Section titled “Throws”RangeError when rate is outside 0.0–1.0 — at construction, so a
rate of 100 meaning “100%” fails at startup rather than silently
logging everything from the first request onward.
Methods
Section titled “Methods”keep()
Section titled “keep()”keep(record, key): boolean;Defined in: src/access-log.ts:247
Decide whether record survives, stamping sample_rate when it does.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
record |
AccessRecord |
The assembled record; mutated when kept under a rate < 1. |
key |
string |
Stable per-call identifier the decision hashes. |
Returns
Section titled “Returns”boolean
