Sitelet https://github.com/Stephenson-Software/trace-client-python/pull/8
Skip to content

Carry a random per-installation ID as the tag install (0.4.0) - #8

Merged
dmccoystephenson merged 1 commit into
mainfrom
install-id
Oct 3, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
install-id

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Ports the per-installation ID from trace-client-java 0.5.0, so the trace server can count distinct installations rather than raw events. Version bumped 0.3.0 → 0.4.0.

What changes

  • install_id= (constructor keyword): an explicit ID, sent as the tag install on every event. Trimmed; None/blank means none; over 255 characters raises ValueError, the same way an overlong version does.
  • install_id_file= (constructor keyword): a path the program chooses. The ID is loaded from it, or a new random UUID is written to it (parent directories created). An explicit install_id= wins over it.
  • TraceClient.install_id_from_file(path) (static): the load-or-create step on its own. The first line matching [A-Za-z0-9_.-]{1,255} is the ID. It never raises: a file that exists but cannot be read is left alone and an in-memory UUID is returned; a write failure also yields an in-memory UUID.
  • client.install_id (property): the ID in use, None when disabled or when none was given.
  • Both options are resolved only after the existing opt-outs (TRACE_USAGE_REPORTING=off, DO_NOT_TRACK=1, enabled=False, no key): a disabled client never generates, reads or writes an ID.
  • An event's own install tag wins. install is added after version and never pushes an event past 32 tags (new MAX_TAGS constant; INSTALL_TAG exported too).
  • No default location: without either option, no ID is made up, nothing is written and no install tag is sent, so existing integrations behave exactly as before.
  • README: new section "Every event carries a random installation ID" (what is sent, where it lives, how to reset, opt-outs stop it), wire-format note updated.

Tests

13 new tests mirroring the Java ones: persist once + reuse (nested parents created), first valid line read, a file with no valid line replaced, unwritable path → in-memory ID (path under a regular file, so it holds when run as root), unreadable path left alone, bad paths never raise, every opt-out writes nothing, explicit ID trimmed and wins over the file, blank = none / overlong rejected, an event's own install tag wins, 32-tag cap respected.

python -m unittest -v (the CI command): 41 tests pass locally on Python 3.8, 3.10 and 3.12.

🤖 Generated with Claude Code

https://claude.ai/code/session_014ztkfamsbEqQfcu76me5SL


drafted by Claude on behalf of Daniel Stephenson

Ports trace-client-java 0.5.0's installation ID. install_id= passes an
explicit ID; install_id_file= loads one from, or writes a new random UUID
to, a path the program chooses. Both are resolved only after the opt-outs,
so a disabled client never makes up or writes an ID. An event's own
install tag wins, and the tag never pushes an event past 32 tags.
TraceClient.install_id_from_file(path) never raises: an unreadable or
unwritable file yields an in-memory ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014ztkfamsbEqQfcu76me5SL
@dmccoystephenson
dmccoystephenson merged commit 3a05deb into main Oct 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant