Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not allow default integrations multiple times #219

Merged
merged 7 commits into from
Jan 30, 2025

Conversation

marandaneto
Copy link
Member

@marandaneto marandaneto commented Jan 28, 2025

💡 Motivation and Context

follow up #217 and #216 (comment)
if multiple instances are created using the with method, we might send data wrongly or too much.

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@marandaneto marandaneto marked this pull request as ready for review January 28, 2025 14:35
@marandaneto marandaneto requested review from ioannisj and a team January 28, 2025 14:38
## 3.11.0 - 2025-01-27

- chore: Session Replay - GA
- fix: session replay and auto capture works with 'with' method ([#217](https://github.com/PostHog/posthog-flutter/pull/217))
- fix: sending cached events null check ([#218](https://github.com/PostHog/posthog-flutter/pull/218))
- fix: session replay and auto capture works with 'with' method ([#217](https://github.com/PostHog/posthog-android/pull/217))
Copy link
Member Author

Choose a reason for hiding this comment

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

ups, copy-pasta error

Copy link

@ioannisj ioannisj left a comment

Choose a reason for hiding this comment

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

I’m not convinced if this is the right approach tbh.

Integrations are effectively handled in a first-come first-served basis, so instance creation order matters here, which could be problematic. If instance creation happens in a non-deterministic order as well, then this will lead to unpredictable results down the line.

Consider this scenario:

  • HostApp integrates with PostHogSDK.
  • HostApp also integrates with SomeOtherSDK.
  • SomeOtherSDK, in turn, integrates with PostHogSDK.
  • Both HostApp and SomeOtherSDK enable all integrations in config (session replay, autocapture, etc.).

In this setup, whichever SDK calls .setup() or .with() first takes precedence. This could introduce inconsistent behavior if the call order is not guaranteed—sometimes the HostApp gets all the active integrations, while other times SomeOtherSDK does.

Broadly speaking, I feel this ties back to how we handle multiple PostHog SDK instances.

Maybe a more robust solution would be to introduce a mechanism in the instance creation process that will ensure a single PostHogSDK instance per API key, each with its own configuration and set of active integrations:

  • Calling .with(apiKey: "project_one_api_key") multiple times should always return the same PostHogSDK instance, ensuring that integrations are installed only once and that events, session replays, and autocapture are delivered to the "project_one_api_key" project.
  • Similarly, calling .with(apiKey: "project_two_api_key") should create a separate instance for that project with its own set of integrations, sending data specifically to the "project_two_api_key" project.

In the scenario above, HostAp and SomeOtherSDK will get a seprate PostHogSDK instance, with all integrations active for each.

wdyt?

@marandaneto
Copy link
Member Author

I’m not convinced if this is the right approach tbh.

Integrations are effectively handled in a first-come first-served basis, so instance creation order matters here, which could be problematic. If instance creation happens in a non-deterministic order as well, then this will lead to unpredictable results down the line.

Consider this scenario:

  • HostApp integrates with PostHogSDK.
  • HostApp also integrates with SomeOtherSDK.
  • SomeOtherSDK, in turn, integrates with PostHogSDK.
  • Both HostApp and SomeOtherSDK enable all integrations in config (session replay, autocapture, etc.).

In this setup, whichever SDK calls .setup() or .with() first takes precedence. This could introduce inconsistent behavior if the call order is not guaranteed—sometimes the HostApp gets all the active integrations, while other times SomeOtherSDK does.

Broadly speaking, I feel this ties back to how we handle multiple PostHog SDK instances.

Maybe a more robust solution would be to introduce a mechanism in the instance creation process that will ensure a single PostHogSDK instance per API key, each with its own configuration and set of active integrations:

  • Calling .with(apiKey: "project_one_api_key") multiple times should always return the same PostHogSDK instance, ensuring that integrations are installed only once and that events, session replays, and autocapture are delivered to the "project_one_api_key" project.
  • Similarly, calling .with(apiKey: "project_two_api_key") should create a separate instance for that project with its own set of integrations, sending data specifically to the "project_two_api_key" project.

In the scenario above, HostAp and SomeOtherSDK will get a seprate PostHogSDK instance, with all integrations active for each.

wdyt?

discussed this offline.

@marandaneto marandaneto requested a review from ioannisj January 29, 2025 21:44
@marandaneto
Copy link
Member Author

@ioannisj dda9648 (#219)

@marandaneto
Copy link
Member Author

@ioannisj @PostHog/team-replay can I has a review?

Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

low context 👍

@marandaneto marandaneto merged commit 958ee59 into main Jan 30, 2025
5 checks passed
@marandaneto marandaneto deleted the fix/multile-integrations branch January 30, 2025 19:16
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