Enable GeoIP resolution in PostHog client initialization#910
Conversation
The PostHog Python SDK defaults to disable_geoip=True, which causes all server-side events to include $geoip_disable: true in their properties. This prevents PostHog from resolving geographic data from the server IP. Set disable_geoip=False in both the singleton Posthog client constructor and the global posthog module configuration so GeoIP lookup is performed on ingested events. https://claude.ai/code/session_01YGVkYhBaCeunwnYGWxLoVN
PR Review: Enable GeoIP resolution in PostHog client initializationOverall this is a small, focused change with clear intent and adequate test coverage. A few things worth addressing before merging: Issues1. Outdated mock accessor style — test_telemetry.py:84The new test uses: call_args[1] is the old-style way of accessing keyword arguments from a MagicMock. Since Python 3.8+, unittest.mock exposes call_args.kwargs which is explicit and immune to positional-vs-keyword argument ordering issues. The other test assertions in this file already use call_args[1] on capture so this is consistent with the existing pattern, but it would be worth standardising on call_args.kwargs in the new test at minimum: 2. Missing CHANGELOG.md updatePer the project's CLAUDE.md conventions, CHANGELOG.md should be updated for production code changes including architecture/configuration changes. This PR intentionally changes telemetry behavior and should have a note in the [Unreleased] section under ### Changed. Observations (non-blocking)Dual configuration paths are intentional but undocumentedThe PR touches two separate PostHog configuration mechanisms:
These are genuinely independent so both changes are necessary. A brief comment in apps.py explaining why disable_geoip is set redundantly (in case future maintainers wonder why the same setting appears in two places) would help. GeoIP resolves the server's IP, not end-user IPsThe PR description is accurate — this resolves geographic data from the server's outgoing IP, not from end users. For self-hosted deployments this reveals where the installation is hosted. Given that OpenContracts is AGPL and often self-hosted in sensitive environments (legal industry), it is worth confirming that operators are aware of what GeoIP data PostHog receives. The existing TELEMETRY_ENABLED opt-out handles this at the feature level, but the in-code comments do not mention the geographic data specifically. Test CoverageThe new test correctly verifies disable_geoip=False is passed at construction time. The setUp/tearDown reset cycle ensures the singleton is rebuilt fresh for each test, so there is no risk of the PostHog class mock not being called. The test logic is sound. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The codecov/patch check was failing because the posthog.disable_geoip line in apps.py had no test coverage. Adds UsersAppGeoIPTestCase that exercises the ready() path with telemetry enabled. Also uses the modern call_args.kwargs accessor in the existing test.
PR Review: Enable GeoIP Resolution in PostHog ClientThe change itself is minimal and the intent is clear. A few items worth discussing before merging: Potentially Dead Configuration (
|
Summary
This PR enables GeoIP resolution in the PostHog client by explicitly setting
disable_geoip=Falseduring initialization. By default, PostHog's server-side SDKs disable GeoIP resolution, but we want to allow PostHog to resolve geographic data from the server's IP address.Key Changes
disable_geoip=Falseparameter when initializing the PostHog client in_get_posthog_client()posthog.disable_geoip = Falseconfiguration in theready()method to ensure GeoIP is enabled for the module-level PostHog instancetest_posthog_client_initialized_with_geoip_enabled()to verify that the PostHog client is initialized with GeoIP enabledImplementation Details
The changes ensure that GeoIP resolution is enabled in both initialization paths:
The test validates that the
disable_geoipparameter is explicitly set toFalseduring client initialization, preventing regression of this behavior.https://claude.ai/code/session_01YGVkYhBaCeunwnYGWxLoVN