From 88809b468398b81b2aca8525261fb421d2c1859a Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sat, 7 Nov 2026 20:16:18 -0700 Subject: [PATCH] Say what the install ID needs and what isBot and pagePath fall back to A documentation sweep against trace-client.ts. The README intro listed the runtime APIs as fetch, AbortController, setTimeout and URL only, though the optional install ID also uses crypto.randomUUID and process.getBuiltinModule when they are present. The heading "Every event carries a random installation ID" overclaimed, since the tag is sent only when the program configures an ID. The README now also covers isBot() treating a missing or blank User-Agent as a bot, and pagePath()'s "/" fallback. The MAX_VERSION_LENGTH doc comment now says it bounds installId too. No behavior changed. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +++++++++ README.md | 15 ++++++++++++--- trace-client.ts | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a70e03f..902d945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,15 @@ against this file to see what a re-vendor would bring. infinities are. The `isBot()` doc comment now says a blank (all-space) User-Agent counts as a bot, as a missing or empty one does. Neither behavior changed. +- The README now says that the optional installation ID uses + `crypto.randomUUID` and `process.getBuiltinModule` when the runtime has + them, and that an `install` tag is sent only when the program gives an + ID. The section heading that said every event carries one is now + "Events can carry a random installation ID". The README also says that + `isBot()` counts a missing or blank User-Agent as a bot, and that + `pagePath()` returns `/` for a non-string or an unparseable URL. The + `MAX_VERSION_LENGTH` doc comment now says it bounds `installId` too. No + behavior changed. ## 0.4.1 — 2026-10-05 diff --git a/README.md b/README.md index bb61a83..4814bf3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ whole library is one file, `trace-client.ts`, and the integration on the program side is meant to stay one call. It uses only `fetch`, `AbortController`, `setTimeout` and `URL` (plus `process.env` where the runtime has one), so it runs in Node 18+, in the Next.js Edge runtime, and -anywhere else that has those four. The Python and +anywhere else that has those four. The optional installation ID also uses +`crypto.randomUUID` and `process.getBuiltinModule` when they are there, and +does without them when they are not; see +[below](#events-can-carry-a-random-installation-id). The Python and Java counterparts are [trace-client-python](https://github.com/Stephenson-Software/trace-client-python) and [trace-client-java](https://github.com/Stephenson-Software/trace-client-java); @@ -46,7 +49,7 @@ constructor (the `version` from your `package.json`, or a constant the build fills in). The hand-added `version` tags can then be dropped if you like; left in, they still win, so nothing changes on the wire. -## Every event carries a random installation ID +## Events can carry a random installation ID Since 0.4.0, every event can also carry the tag `install`: a random ID for the installation, so the trace server can count **distinct installations** @@ -128,7 +131,7 @@ Besides `version`, `key`, `enabled` and `env`, the constructor's options take: |---|---|---| | `timeoutMs` | `5000` | How long one request may take before it is aborted. Anything but a positive finite number — `0`, negative, `NaN`, `Infinity`, not a number — falls back to the default. A longer one than `2147483647` (about 24.8 days, the most a timer can hold) is held to that. | | `fetch` | the global `fetch` | The `fetch` to send with, for a runtime that provides its own or for tests. One that ignores its abort signal is given up on at the timeout all the same, and anything it does later is discarded. | -| `installId` | none | The installation's ID, sent as the tag `install`; see [above](#every-event-carries-a-random-installation-id). | +| `installId` | none | The installation's ID, sent as the tag `install`; see [above](#events-can-carry-a-random-installation-id). | | `installIdFile` | none | A file holding the installation's ID, created with a random UUID on first run by an enabled client. | | `debug` | none | Called with one line per dropped report, prefixed `[trace] `. A `debug` that throws, or an `async` one that rejects, is ignored; its promise is not waited for. | @@ -255,6 +258,12 @@ capped at 200 characters), `isBot()` keeps crawlers, link previewers and uptime monitors out of the count, and the middleware above never reads anything else off the request. +`pagePath()` always returns a path starting with `/`: one is added when it +is missing, and a non-string or an absolute URL that cannot be parsed gives +`/`. `isBot()` counts a request with a missing, empty or blank `User-Agent` +as a bot, since every real browser sends one, so such requests are not +reported as page views. + **The opt-out.** Three environment variables, all optional, on top of `TRACE_USAGE_REPORTING` / `DO_NOT_TRACK` (which the client checks by itself): diff --git a/trace-client.ts b/trace-client.ts index 946bf71..860d07a 100644 --- a/trace-client.ts +++ b/trace-client.ts @@ -162,7 +162,7 @@ export interface ReportOptions { export class TraceClient { static readonly IN_FLIGHT_CAPACITY = 256; static readonly TIMEOUT_MS = 5000; - /** The longest program version accepted, after trimming. */ + /** The longest program version, or `installId`, accepted after trimming. */ static readonly MAX_VERSION_LENGTH = 255; /** The `install` tag is not added to an event that already has this many tags; its own tags are not capped. */ static readonly MAX_TAGS = 32;