Repository navigation
fix: send persisted anonymousId and userId with telemetry events - #56
claudiacodacy wants to merge 1 commit into
Conversation
The Segment SDK stores its own anonymousId and userId under /tmp/analytics-kotlin/<writeKey>, which is cleared on reboot. Every restart showed up as a new install, and signed-in users lost their userId until the next login. Set both ids on every event from the plugin's persisted settings instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
Pull Request Overview
The event enrichment can send a stale authenticated userId after sign-out because a null persisted userId does not clear the existing event identity. This should be fixed before merging.
All required identity and plugin-registration test scenarios are missing, leaving the acceptance criteria unverified. Codacy reports the PR as up to standards.
About this PR
- Add automated tests covering persisted identity enrichment, sign-out behavior, and plugin registration before merging.
Test suggestions
- Verify events receive the persisted anonymousId after analytics SDK storage is cleared or unavailable
- Verify signed-in users’ events receive the persisted userId
- Verify unsigned users’ events do not retain or send a stale userId
- Verify the enrichment plugin is registered and executes for tracked events
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify events receive the persisted anonymousId after analytics SDK storage is cleared or unavailable
2. Verify signed-in users’ events receive the persisted userId
3. Verify unsigned users’ events do not retain or send a stale userId
4. Verify the enrichment plugin is registered and executes for tracked events
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| override fun execute(event: BaseEvent): BaseEvent { | ||
| val state = Config.instance.state | ||
| event.anonymousId = state.anonymousId | ||
| state.userId?.let { event.userId = it.toString() } |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Clear the event identity when the persisted userId is absent so logout cannot send a stale SDK userId.
| state.userId?.let { event.userId = it.toString() } | |
| event.userId = state.userId?.toString() |
Problem
The Segment Kotlin SDK (1.21.0) stores its own
anonymousIdanduserIdin/tmp/analytics-kotlin/<writeKey>/(StorageImpl.kt)./tmpis cleared on reboot, so after every restart:anonymousIdand counts as a new installuserIduntil they log in againThe plugin already persists a stable
anonymousIdand theuserIdinCodacyPluginSettings.xml(Config.kt), but only sends them inside the event properties, not as the message's own ids.What this looks like in the warehouse (
jetbrains_ides, last 90 days):Only ~16% of JetBrains events carry a
user_id, so JetBrains install counts are inflated and install-based retention can't be measured.Fix
Add a Segment enrichment plugin that sets
anonymousId, anduserIdwhen signed in, on every event from the persisted plugin settings.Testing
./gradlew buildPluginbefore merging.jetbrains_ides.tracks:anonymous_idshould stay the same across IDE restarts and reboots, anduser_idshould be set for signed-in users.Related: OD-700 (IDE telemetry).
🤖 Generated with Claude Code