feat: add hashed user tracking #1332
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1332"
general
weight: 0.35
nachoBonafonte
TL; DR:
Watch video https://app.revyl.ai/sessions/report?token=fab9bd09-6f8b-42bd-81c4-6831145c8f74
Summary
Adds
user.hashto every span and log record, so telemetry can tell users apart without saying who they are. I choseuser.hashoveruser.idfor privacy. Until the app signs a user in, the hash is a random value per installation.setHashedUser(_:), the only setter, takes raw identifiers such as an account ID and an email, and hashes them with HMAC-SHA256 under a key of the installation or one the app gives. The identifiers are never stored, stamped or logged.reset()returns to a new random value.Ref: https://github.com/open-telemetry/opentelemetry-swift/issues/990
Testing
Updated hacker news demo
Limitations
Again, not doing
user.idbecause that complicates the privacy stuff.Checklist
swift test --enable-all-traitspasses locallyTests/IntegrationTestsare updated. Anything that adds, removes orrenames a span, log record, event name, or attribute emitted by an
instrumentation (
Sources/Instrumentation/) must be exercised byIntegrationTestScenarioinExamples/HackerNewsDemoand asserted onin
Tests/IntegrationTests/Assertions. Runmake integ-tests-iostoverify, and see
Tests/IntegrationTests/README.md.---
---
Users
Status: experimental. Names may change in any release.
user.hashis atdevelopmentstability in the semantic conventions.The
UserManager** class tells users apart without exporting who they are. It holds one hash, stores it across launches, and two processors stamp it asuser.hashon spans and log records. Until the app sets a user, the hash is a random value, so telemetry from one installation correlates before anyone signs in.!A timeline of one installation. The first launch generates and stores random hash A, and a restart restores it. Calling setHashedUser with an id and an email stores their HMAC in its place, and reset stores a new random hash B. A span that starts before setHashedUser and ends after it keeps A. The id and email are never stored, stamped or logged.
Register both processors, ahead of the exporter:
Set the user at sign-in and at each signed-in launch, and reset at sign-out:
Instance properties
<dl>
<dt><code>userHash</code> <em>Read only</em></dt>
<dd>The current hash. Never empty.</dd>
</dl>
user.hash<dl>
<dt>On a span</dt>
<dd>The hash current when the span started. A span that outlives a sign-in keeps the user who started it.</dd>
<dt>On a log record</dt>
<dd>The hash current when the record was emitted.</dd>
</dl>
A span that already carries
user.hashwhen it starts, or a record that already carries it, is left alone. Attribute limits apply: a span or record already at its attribute count limit gets nouser.hash, and a length limit under 64 truncates it. The SDK applies a span's limits, but appliesLogLimitsonly before processors run, so giveUserLogRecordProcessorthe limits you give theLoggerProviderBuilder:Hashing
setHashedUser(_:)computes HMAC-SHA256 and writes it as 64 lowercase hexadecimal digits. A plain SHA-256 would not hide an email address: anyone with the telemetry could hash a list of addresses and compare. The key prevents that, so where the key lives decides what the hash protects.|
hashKey| Same user on two devices | Who can test a guess at an identifier || ----------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| None, the default | Different hashes, unless one was restored from the other's backup | Whoever holds that installation's storage or a backup of it, where its random key is |
| Given by the app | The same hash | Whoever holds the key, or extracts it from the app |
Order matters. Each identifier is length-prefixed, so
["ab", "c"]and["a", "bc"]differ, and composed to Unicode NFC, so equal strings hash alike. Normalize case and whitespace before the call.Lifecycle
| Event | Hash | Source |
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| First launch | Random, stored | This module |
| Relaunch | Restored | [
UserDefaults][defaults]: "a persistent store for app-specific and system-wide settings" ||
setHashedUser(_:)| HMAC, stored | [UserDefaults][defaults]: "updates its in-memory version", then "writes the value to disk asynchronously" ||
reset()| New random, stored | This module. The installation's key stays, so a returning user gets the same hash || Device backup | Included, with the key | [
UserDefaults][defaults]: "includes any persistent defaults databases in the backup data" || App deleted and reinstalled | New random, and new key | Not documented |
| Launch before the first unlock | If storage is unreadable, a new random hash overwrites the stored one, and the next
setHashedUser(_:)overwrites the key | Not documented; not verified |<dl>
<dt>Gaps</dt>
<dd>The installation's key is in <code>UserDefaults</code>, which Apple says <a href="https://developer.apple.com/documentation/foundation/userdefaults">"stores information on disk in an unencrypted format"</a>. A crash reported on the next launch carries the user current then, not the one who crashed. Each manager reads storage only when created, so use one per storage key, in one process: the last to write wins. A new <code>hashKey</code> takes effect at the next <code>setHashedUser(_:)</code>. Metrics carry no <code>user.hash</code>.</dd>
<dt>Opting out</dt>
<dd>Leave the processors out. Nothing is generated or stored until a manager is created; a processor creates one at its first span or record.</dd>
<dt>Privacy manifest</dt>
<dd>Apps must declare <code>UserDefaults</code> in <code>PrivacyInfo.xcprivacy</code>, <a href="https://developer.apple.com/documentation/bundleresources/describing-use-of-required-reason-api">as a required-reason API</a>. This package ships no manifest.</dd>
</dl>
[defaults]: https://developer.apple.com/documentation/foundation/userdefaults
Instance methods
UserManager<dl>
<dt><code>init(hashKey:userDefaults:storageKey:)</code></dt>
<dd>Restores the stored hash, or generates and stores a random one. <code>hashKey</code> keys <code>setHashedUser(_:)</code>; an empty one counts as none. Storage defaults to <code>.standard</code>, under <code>otel-user-hash</code>.</dd>
<dt><code>setHashedUser(_:)</code></dt>
<dd>Takes a list of raw identifiers, such as an account ID and an email address, hashes them and sets the result. The identifiers are never stored, stamped or logged. A list with nothing in it, or only empty strings, changes nothing. Needs CryptoKit.</dd>
<dt><code>reset()</code></dt>
<dd>Replaces the hash with a new random value.</dd>
</dl>
Each change posts
UserManager.didChangeNotification, with the manager as its object.UserManagerProvider<dl>
<dt><code>register(userManager:)</code> <em>Static</em></dt>
<dd>Shares a manager, such as one with a <code>hashKey</code>. Processors read it at each span or record, so one registered later still reaches them.</dd>
<dt><code>getInstance()</code> <em>Static</em></dt>
<dd>Returns the shared manager, creating a default one on first use.</dd>
</dl>
Specifications
| Name | Kind | Specification |
| ----------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
user.hash| Attribute | OpenTelemetry semantic conventions, asSemanticConventions.User.hash|The convention describes
user.hashas a "unique user hash to correlate information for a user in anonymized form". The random value that stands in before sign-in is this module's own use.Compatibility
| Platform | Minimum | Stamps
user.hash|setHashedUser(_:)| Tested on || --------------------------------------------- | --------------- | :----------------: | :-----------------: | ------------------------------------------- |
| iOS | 15 | ✓ | ✓ | Simulator: unit tests and integration tests |
| macOS | 12 | ✓ | ✓ | Unit tests |
| iPadOS, tvOS, watchOS, visionOS, Mac Catalyst | 15, 15, 8, 1, — | ✓ | ✓ | — |
| Linux, Windows | — | ✓, random only | —, no CryptoKit | — |
Untested rows describe the code, not observed telemetry. The integration tests cover the generated hash; unit tests cover
setHashedUser(_:).See also
session.id, which changes whileuser.hashpersistsapp.installation.id, which the app cannot setHMACandUserDefaultsAwsUIDManager: the design this module started from, which stamps a rawuser.id