Skip to content

feat(MBL-2543): move analytics storage when switching to a public key - #926

Open
sydneycollins-cio wants to merge 20 commits into
mbl-2543-keyfrom
mbl-2543-storage
Open

sydneycollins-cio wants to merge 20 commits into
mbl-2543-keyfrom
mbl-2543-storage

Conversation

@sydneycollins-cio

@sydneycollins-cio sydneycollins-cio commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Keep the user's identity and unsent events when an app switches over to its public key.

  • Before analytics starts, copy the anonymous ID, user ID and traits from the old key to the new key. The old key keeps its copy.
  • Finished batches are left alone. Segment (1.24.1) uploads every finished file in the queue folder with the key written inside it, and the default flush policies flush at start.
  • Unfinished batches from earlier keys are read in the background. Each complete event is added to the new key's queue as is, and the old file is deleted.

Costs

  • Old finished batches go to the old source, so they're lost if the old key is revoked before they upload.
  • A crash part way through the replay can send unfinished batch events twice with the same messageIds.
  • Old batches upload to the new key's API host, so a switch between US and EU sends them to the other region's host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


  • java_layout: mbl-2543-storage (1792522238)
  • kotlin_compose: mbl-2543-storage (1792522227)

Commit 377741b · CI run

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.07080% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.54%. Comparing base (8ad61d0) to head (377741b).

Files with missing lines Patch % Lines
...tapipelines/migration/AnalyticsStorageMigration.kt 80.64% 3 Missing and 15 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             mbl-2543-key     #926      +/-   ##
==================================================
+ Coverage           74.48%   74.54%   +0.06%     
- Complexity           2395     2439      +44     
==================================================
  Files                 283      284       +1     
  Lines               13376    13483     +107     
  Branches             2282     2317      +35     
==================================================
+ Hits                 9963    10051      +88     
- Misses               2600     2604       +4     
- Partials              813      828      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Build available to test
Version: mbl-2543-storage-SNAPSHOT
Repository: https://central.sonatype.com/repository/maven-snapshots/

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

📏 SDK Binary Size Comparison Report

Module Last Recorded Size Current Size Change in Size
core 50.02 KB 50.02 KB ✅ No Change
datapipelines 43.30 KB 48.87 KB ⬆️ +5.57KB
messagingpush 75.18 KB 75.18 KB ✅ No Change
messaginginapp 165.14 KB 165.14 KB ✅ No Change
messaginginbox 61.19 KB 61.19 KB ✅ No Change
tracking-migration 22.89 KB 22.89 KB ✅ No Change
location 20.40 KB 20.40 KB ✅ No Change
geofence 225.77 KB 225.77 KB ✅ No Change

@sydneycollins-cio
sydneycollins-cio marked this pull request as ready for review October 7, 2026 18:44
@sydneycollins-cio
sydneycollins-cio requested a review from a team as a code owner October 7, 2026 18:44
@sydneycollins-cio
sydneycollins-cio marked this pull request as draft October 7, 2026 18:44

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@sydneycollins-cio
sydneycollins-cio marked this pull request as ready for review October 7, 2026 20:32
@sydneycollins-cio
sydneycollins-cio added this pull request to stack #932 October 7, 2026 20:57

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s to the newest key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mahmoud-elmorabea mahmoud-elmorabea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the migration! 💯

One thing: The migration logic is making me a bit nervous 😅 I think we can make this simpler and keep file IO off the init path, see my comment on CustomerIO.kt.

Comment thread datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt Outdated
Comment thread datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt Outdated
…on key switch

Finished batches upload as they are, since analytics uploads every finished file
with the key written in it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

sydneycollins-cio and others added 2 commits October 19, 2026 13:48
…unknown files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SDK versions before 4.5.3 don't save their key, so when no saved key is
found and the new key is public, look through the analytics-android-*
storages. Take the most recently used one whose saved analytics settings
name the Customer.io destination. If none do, take a single other key
with no settings, skip storage owned by Segment's own SDK, and log and
skip when there are several.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mahmoud-elmorabea mahmoud-elmorabea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a lot simpler now! 💯 Two things left on the move.

sydneycollins-cio and others added 2 commits October 20, 2026 14:20
…en batches

Copying segment.app.version/build, the legacy build and the device id keeps
Segment from tracking Application Installed again after a key switch. Open
batches are moved only for the previous key and keys whose settings name
our destination, so Segment's own open batch is left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit efcc32e. Configure here.

Identity stays all or nothing so one key's anonymousId never pairs with
another's userId. App version, build and device id are each copied when
missing, so a partial earlier copy can't cause Application Installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants