Repository navigation
trace-client 0.2.0: environment opt-outs and disabledReason - #1
Merged
Merged
Conversation
The constructor now checks TRACE_USAGE_REPORTING=off|false|0|no and
DO_NOT_TRACK=1|true|yes before enabled and the key, as trace-client-java and
trace-client-python 0.2.0 do, and exposes why a client sends nothing as
disabledReason ("environment", "config", "no key"; null when on). The
environment is process.env when the runtime has one, read by literal name
and guarded so a runtime without process (or with an unreadable env) opts
nothing out and never throws; the new env option replaces it.
Everything new hangs off TraceClient as static members, so the file's
exported values stay exactly those of 0.1.0 and existing wrappers (the
Next.js sites, dpc-mcp-server's CommonJS derivation) need no change.
User-Agent and header bumped to 0.2.0; tests, README and CHANGELOG updated.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
trace-client-js is brought level with trace-client-java and trace-client-python 0.2.0: the constructor now honours
TRACE_USAGE_REPORTING=off|false|0|noandDO_NOT_TRACK=1|true|yesbeforeenabledand the key, and the reason a client sends nothing is exposed asdisabledReason("environment","config","no key";nullwhen on). Until now every JavaScript consumer had to re-implement that check in its own wrapper. The file stays one file with zero dependencies, and it stays API-compatible with 0.1.0: its exported values are exactly the same four (TRACE_CLIENT_VERSION,TraceClient,pagePath,isBot) because everything new is a static member ofTraceClient, so the Next.js sites' wrappers and dpc-mcp-server's CommonJS derivation (which checks that export list) need no change on re-vendor.trace-client.tsprocess.envwhen the runtime has one, read by the two literal names (so Next.js can inline them for the Edge runtime) inside a guard: noprocess, or aprocess.envthat throws, opts nothing out and never fails.processis declared locally, so the file still type-checks against ES2022 + DOM with no@types/node, and also alongside@types/nodein a consumer project.envoption replacesprocess.env(Workers-style runtimes, tests).disabledReasongetter, fixed at construction (close()turnsenabledoff but keeps the reason);TraceClient.REASON_ENVIRONMENT/REASON_CONFIG/REASON_NO_KEY,ENV_TRACE_USAGE_REPORTING/ENV_DO_NOT_TRACK, andTraceClient.environmentOptsOut(env?).TRACE_CLIENT_VERSIONand theUser-Agentbumped to 0.2.0.tests/trace-client.test.ts: the documented values and near-misses, precedence (environment, thenenabled, then key), defaultprocess.envreading,envreplacingprocess.env, a runtime with noprocessand one whose env throws, a hostileenv, the unchanged export list and 0.1.0 call shapes. The developer's own opt-out variables are cleared for the file so the delivery tests are not silently turned into no-ops.README.md,CHANGELOG.md,package.json/package-lock.json: a "Turning it off from the environment" section, the 0.2.0 entry, version 0.2.0.Verification:
npm run typecheckandnpm test(32 tests) pass locally on Node 22.23. The new file was also type-checked with@types/node@22present, re-derived through dpc-mcp-server'stools/vendor-trace-client.js --from(derivation accepted; itsnpm test75/75 with 0.2.0), and dropped into danielstephenson-dot-dev'sutils/trace-client.ts(its four usage-reporting vitest files 30/30 andtsc --noEmitclean). Those consumer checks were run in scratch clones only; nothing was pushed to them. Merging and tagging0.2.0are left to the coordinator.🤖 Generated with Claude Code
drafted by Claude on behalf of Daniel Stephenson