Add hook timestamp to telemetry reporting#32
Open
rishiy15 wants to merge 1 commit into
Open
Conversation
JillRegan
approved these changes
Jun 26, 2026
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.
Summary
Adds a
ts(epoch-milliseconds) field to both telemetry event schemas (agent_hook_executionandagent_hook_install), stamping when each hook fired. The 1Password app maps this to the Snowplow device-created timestamp, giving downstream analytics an accurate event time rather than relying on ingestion time.Changes
lib/telemetry.shts_json_fragment()helper that produces the,"ts":<epoch_ms>JSON fragment fromcurrent_time_ms(). It's guarded by a numeric regex check, so an unreadable/non-numeric clock yields an empty string instead of a malformed JSON line.write_execution_event()andwrite_install_event()now append thetsfragment to their emitted JSON lines.tests/lib/telemetry.batstsis present and an unquoted integer (so it parses as a JSON number, not a string) in both execution and install events.python3, when available) for the install event to confirm the line stays valid with the new field.Testing Done
bats tests/lib/telemetry.batssuite — all 31 tests pass.tspresent (happy path): With a readable clock, bothwrite_execution_eventandwrite_install_eventemit"ts":<int>. Tests assert the value is an unquoted integer (\"ts\":[0-9]+) and explicitly reject a quoted string ("ts":"...") so it deserializes as a JSON number, and the install event is round-tripped throughpython3 json.loads` to confirm the full line is still valid JSON.tsabsent (backwards compatibility):ts_json_fragment()returns an empty string whencurrent_time_ms()yields a non-numeric/unreadable value, so the field is simply omitted. The resulting event line is identical to the pre-change schema, which the existing structure tests continue to cover. Consumers must treattsas optional — events from older hook bundles, or from a host with an unreadable clock, will not carry it.tsis purely additive — no existing field changed name, type, or position — so older parsers ignoring unknown keys are unaffected.Notes
tsfield is optional by construction — if the clock can't be read, the field is omitted and the rest of the event is unaffected.