Skip to content

Enforce (or provide user-facing warnings) instantiating the Python client as a singleton #152

@dmarticus

Description

@dmarticus

Full context can be found here: https://posthog.slack.com/archives/C03P7NL6RMW/p1733514026622539, but here's the summary for external stakeholders:

Issue:

  • Users were experiencing dropped events when using the Python SDK
  • Feature flag events were being captured but other events weren't
  • Investigation revealed multiple SDK client instances were being instantiated
  • No warnings/exceptions were thrown on multiple client instantiations

Root Cause:

  • The SDK doesn't enforce a singleton pattern for client instances
  • Multiple client instances in the same application can cause event capture issues
  • This becomes particularly problematic in containerized environments like Kubernetes

Solution:

  • Implement a singleton factory pattern to prevent multiple client instantiations
  • Add explicit warnings/exceptions when users try to create multiple clients
  • Update documentation to:
    • Clearly explain the singleton requirement
    • Provide best practices for client instantiation
    • Include guidance for complex infrastructure setups

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions