fix(analytics): isolate AnalyticsMessages and HttpService per instance [SDK-109]#985
Open
tylerjroach wants to merge 2 commits into
Open
fix(analytics): isolate AnalyticsMessages and HttpService per instance [SDK-109]#985tylerjroach wants to merge 2 commits into
tylerjroach wants to merge 2 commits into
Conversation
…e [SDK-109] Two MixpanelAPI instances configured with different tokens and no explicit instanceName silently shared a single AnalyticsMessages worker (and hence its MPConfig and HttpService), so events for the second instance were POSTed to the first instance's server URL. Additionally, runtime setServerURL calls updated MPConfig endpoints but never refreshed the HttpService serverHost captured at construction. - AnalyticsMessages.getInstance now takes a token and keys by MPConfig.resolveInstanceKey(instanceName, token), mirroring MixpanelAPI.getInstance. - getPoster re-syncs serverHost on every call, so setServerURL propagates to the HttpService. - Extracted the instanceName-or-token fallback into MPConfig.resolveInstanceKey to keep the five prior copies in sync. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
assertEquals falls back to reference equality when the type doesn't override equals(), which HttpService doesn't — so the assertion works but reads as a value-equality check. assertSame is the idiomatic JUnit choice for identity and makes intent explicit.
Contributor
Author
|
Pushed |
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
Two
MixpanelAPIinstances configured with different tokens and no explicitinstanceNamesilently shared a singleAnalyticsMessagesworker (and therefore itsMPConfigandHttpService), so events for the second instance were POSTed to the first instance's server URL. Independently, runtimesetServerURLcalls updatedMPConfigendpoints but never refreshed theHttpServiceserverHostcaptured at construction.Changes
AnalyticsMessages.getInstancenow takes atokenand keyssInstancesbyMPConfig.resolveInstanceKey(instanceName, token), mirroringMixpanelAPI.getInstanceand matching iOSMixpanelManagerbehavior.AnalyticsMessages.getPosterre-syncsserverHost(in addition tobackupHostand the error listener) on every call, sosetServerURLpropagates to the poster.HttpService.setServerHost/getServerHost; the constructor delegates tosetServerHostso the empty-check +DEFAULT_SERVER_HOSTfallback lives in one place.instanceName ?? tokenfallback intoMPConfig.resolveInstanceKey— the five prior inline copies (plus three in tests) now call it, avoiding future drift.mInstanceNamefield onAnalyticsMessages.Workaround
Users on older SDK versions can side-step both bugs by giving each
MixpanelOptionsa distinctinstanceNameand setting the server URL viaMixpanelOptions.serverURL(...)(which is applied before the firstgetPoster()call, soHttpServiceis constructed with the right host on first creation).