Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(growth): region-local EU dispatch for signup enrichment (#79254)

Matt Brooker41c4b9ac6743
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 4010d3238871..9ec3f2f3d4dc 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -351,14 +351,19 @@ SESSION_COOKIE_CREATED_AT_KEY = get_from_env("SESSION_COOKIE_CREATED_AT_KEY", "s
# tests that assert posthoganalytics.feature_enabled call counts.
SESSION_RISK_ENABLED = get_from_env("SESSION_RISK_ENABLED", not TEST, type_cast=str_to_bool)
# Kill switch for the real-time signup enrichment workflow (products/growth/backend/enrichment).
-# Off by default: it must stay off until the launch fill-rate/failure alert is in place, and v0 is
-# US-only. Fire-and-forget from signup, so this only gates whether the workflow is dispatched at all.
+# Off by default: it must stay off until the launch fill-rate/failure alert is in place. Also the
+# de facto per-region toggle, since it is the only region-specific control — dispatch itself is
+# open to both US and EU (see get_instance_region gate in signup_enrichment/trigger.py), so a
+# region stays enrichment-free only by leaving this unset there. Fire-and-forget from signup, so
+# this only gates whether the workflow is dispatched at all.
GROWTH_SIGNUP_ENRICHMENT_ENABLED = get_from_env("GROWTH_SIGNUP_ENRICHMENT_ENABLED", False, type_cast=str_to_bool)
# The internal analytics project the enrichment pipeline reads/writes bridge and mirror data
-# against (products/growth/backend/enrichment). Defaults to project 2, the internal project the
-# enrichment group properties are projected onto; env-overridable since that id differs across
-# cloud deployments.
-GROWTH_ENRICHMENT_INTERNAL_TEAM_ID = get_from_env("GROWTH_ENRICHMENT_INTERNAL_TEAM_ID", 2, type_cast=int)
+# against (products/growth/backend/enrichment). Region-defaulted to the deployment's own internal
+# project (the same team split the usage report uses), so enrichment lookups never touch another
+# region's project.
+GROWTH_ENRICHMENT_INTERNAL_TEAM_ID = get_from_env(
+ "GROWTH_ENRICHMENT_INTERNAL_TEAM_ID", 1 if (CLOUD_DEPLOYMENT or "").upper() == "EU" else 2, type_cast=int
+)
# Session keys for risk-based step-up (posthog/session/risk.py). Named so every reader/writer shares
# one source of truth, like SESSION_COOKIE_CREATED_AT_KEY above.
SESSION_STEP_UP_REQUIRED_KEY = get_from_env("SESSION_STEP_UP_REQUIRED_KEY", "step_up_required")
diff --git a/posthog/temporal/signup_enrichment/trigger.py b/posthog/temporal/signup_enrichment/trigger.py
index 0313311e22db..9a51da01a277 100644
--- a/posthog/temporal/signup_enrichment/trigger.py
+++ b/posthog/temporal/signup_enrichment/trigger.py
@@ -1,8 +1,8 @@
"""Fire-and-forget dispatch of the signup enrichment workflow from the request path.
-Every guard lives here so the signup serializer stays a one-line call. Dispatch is
-gated by the kill switch and US-only for v0, and never raises — a Temporal outage
-degrades to "enrichment did not run". The provider key lives on the workers only. Personal-domain
+Every guard lives here so the signup serializer stays a one-line call. Dispatch is gated by the
+kill switch and the Cloud region (self-hosted never dispatches), and never raises — a Temporal
+outage degrades to "enrichment did not run". The provider key lives on the workers only. Personal-domain
signups get no provider lookup, but the work-vs-personal email signal is recorded
for every signup so consumers can read it either way.
"""
@@ -65,8 +65,9 @@ def start_signup_enrichment_workflow(
# web pods silently never dispatching (also keeps the key off the public web fleet).
if not settings.GROWTH_SIGNUP_ENRICHMENT_ENABLED:
return
- # v0 is US-only.
- if get_instance_region() != "US":
+ # Cloud only — self-hosted has no Harmonic key or internal project to score against. The
+ # flag above is the real per-region toggle; it stays unset in EU until enabled there.
+ if get_instance_region() not in ("US", "EU"):
return
domain = domain_from_email(email)
diff --git a/posthog/temporal/signup_enrichment/workflow.py b/posthog/temporal/signup_enrichment/workflow.py
index cceffeae7eaf..016d809648d6 100644
--- a/posthog/temporal/signup_enrichment/workflow.py
+++ b/posthog/temporal/signup_enrichment/workflow.py
@@ -15,7 +15,7 @@ from temporalio import activity, workflow
from temporalio.common import RetryPolicy
from posthog.exceptions_capture import capture_exception
-from posthog.ph_client import get_client
+from posthog.ph_client import get_regional_ph_client
from posthog.temporal.common.base import PostHogWorkflow
from posthog.temporal.common.logger import get_logger
from posthog.temporal.common.utils import close_db_connections
@@ -100,7 +100,12 @@ async def enrich_signup_organization_activity(
logger.info("signup_enrichment_recheck_skipped_org_deleted")
return {"matched": False, "fields_filled": 0, "org_deleted": True}
- pha_client = get_client()
+ # Region-local on purpose: EU enrichment lands in the EU internal project, US in US — the
+ # same split the usage report uses. Never fall back to a cross-region client here.
+ pha_client = get_regional_ph_client()
+ if pha_client is None:
+ logger.error("signup_enrichment_no_regional_client")
+ return {"matched": False, "fields_filled": 0}
try:
fields = await enrich_organization(
diff --git a/posthog/temporal/tests/signup_enrichment/test_activity.py b/posthog/temporal/tests/signup_enrichment/test_activity.py
index 7f955e21ab8c..631cb5d8e040 100644
--- a/posthog/temporal/tests/signup_enrichment/test_activity.py
+++ b/posthog/temporal/tests/signup_enrichment/test_activity.py
@@ -24,7 +24,7 @@ _INPUTS = SignupEnrichmentInputs(organization_id="org-1", distinct_id="d1", doma
def _patches(*, enrich_return, deterministic=None):
pha_client = MagicMock()
return pha_client, (
- patch(f"{_MODULE}.get_client", return_value=pha_client),
+ patch(f"{_MODULE}.get_regional_ph_client", return_value=pha_client),
patch(f"{_MODULE}.enrich_organization", AsyncMock(**enrich_return)),
patch(f"{_MODULE}._deterministic_company_type", return_value=deterministic),
patch(f"{_MODULE}.capture_signup_enrichment_snapshot"),
diff --git a/posthog/temporal/tests/signup_enrichment/test_trigger.py b/posthog/temporal/tests/signup_enrichment/test_trigger.py
index 9f084025eab2..136df39e4015 100644
--- a/posthog/temporal/tests/signup_enrichment/test_trigger.py
+++ b/posthog/temporal/tests/signup_enrichment/test_trigger.py
@@ -60,7 +60,23 @@ def test_missing_harmonic_key_still_dispatches():
@override_settings(GROWTH_SIGNUP_ENRICHMENT_ENABLED=True, HARMONIC_API_KEY="key")
-def test_non_us_region_never_dispatches():
+def test_eu_region_dispatches_when_enabled():
+ on_commit, connect, run, region, record = _dispatch_mocks(region="EU")
+ with on_commit, connect as connect_mock, run, region, record:
+ start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")
+ connect_mock.assert_called_once()
+
+
+@override_settings(GROWTH_SIGNUP_ENRICHMENT_ENABLED=True, HARMONIC_API_KEY="key")
+def test_self_hosted_region_never_dispatches():
+ on_commit, connect, run, region, record = _dispatch_mocks(region="DEV")
+ with on_commit, connect as connect_mock, run, region, record:
+ start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")
+ connect_mock.assert_not_called()
+
+
+@override_settings(GROWTH_SIGNUP_ENRICHMENT_ENABLED=False, HARMONIC_API_KEY="key")
+def test_kill_switch_off_never_dispatches_in_eu_either():
on_commit, connect, run, region, record = _dispatch_mocks(region="EU")
with on_commit, connect as connect_mock, run, region, record:
start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")
diff --git a/posthog/temporal/tests/signup_enrichment/test_workflow.py b/posthog/temporal/tests/signup_enrichment/test_workflow.py
index d0666044fb06..9a48b9011470 100644
--- a/posthog/temporal/tests/signup_enrichment/test_workflow.py
+++ b/posthog/temporal/tests/signup_enrichment/test_workflow.py
@@ -29,7 +29,7 @@ async def _run(enrich_side_effect) -> tuple[dict, MagicMock, AsyncMock, MagicMoc
pha_client = MagicMock()
enrich = AsyncMock(side_effect=enrich_side_effect)
with (
- patch(f"{_MODULE}.get_client", return_value=pha_client),
+ patch(f"{_MODULE}.get_regional_ph_client", return_value=pha_client),
patch(f"{_MODULE}.enrich_organization", enrich),
patch(f"{_MODULE}._deterministic_company_type", return_value=None),
patch(f"{_MODULE}.capture_signup_enrichment_snapshot") as snapshot,
@@ -103,7 +103,7 @@ async def test_recheck_skips_deleted_organization():
)
with (
patch(f"{_MODULE}.enrich_organization") as enrich_mock,
- patch(f"{_MODULE}.get_client") as client_mock,
+ patch(f"{_MODULE}.get_regional_ph_client") as client_mock,
patch("posthog.models.Organization.objects") as org_objects,
):
org_objects.filter.return_value.exists.return_value = False
diff --git a/products/growth/backend/enrichment/bridge.py b/products/growth/backend/enrichment/bridge.py
index b658fcdf4ca8..891e00155153 100644
--- a/products/growth/backend/enrichment/bridge.py
+++ b/products/growth/backend/enrichment/bridge.py
@@ -24,6 +24,7 @@ from django.conf import settings
from posthog.models.group.util import get_group_by_key
from posthog.models.group_type_mapping import get_group_types_for_project
from posthog.models.team import Team
+from posthog.utils import get_instance_region
from products.growth.backend.enrichment.writer import ORGANIZATION_GROUP_TYPE
@@ -76,6 +77,10 @@ def _organization_group_type_index(team: Team) -> int:
def read_clay_bridge_inputs(*, organization_id: str) -> ClayBridgeInputs:
"""Fetch the Clay-written score inputs for one org. Raises if the group store can't be read."""
+ # Clay only ever wrote to the US internal project, so outside US there is nothing to read —
+ # skip the lookup entirely instead of querying a project the bridge never touched.
+ if get_instance_region() != "US":
+ return ClayBridgeInputs()
# The internal project the enrichment group properties are projected onto, and the same one
# the ProductLed_Outbound consumer reads them back from (ee/billing/dags/productled_outbound_targets.py).
team = Team.objects.get(id=settings.GROWTH_ENRICHMENT_INTERNAL_TEAM_ID)
diff --git a/products/growth/backend/management/commands/backfill_signup_enrichment.py b/products/growth/backend/management/commands/backfill_signup_enrichment.py
index e6cb76737f92..804c08ec3ed1 100644
--- a/products/growth/backend/management/commands/backfill_signup_enrichment.py
+++ b/products/growth/backend/management/commands/backfill_signup_enrichment.py
@@ -44,9 +44,9 @@ class Command(BaseCommand):
# must not defeat it if it was turned off for a compliance, cost, or vendor reason.
if not settings.GROWTH_SIGNUP_ENRICHMENT_ENABLED:
raise CommandError("Signup enrichment is disabled (GROWTH_SIGNUP_ENRICHMENT_ENABLED); refusing to dispatch")
- # Enrichment is US-only for v0 (mirrors the signup-path region gate).
- if get_instance_region() != "US":
- raise CommandError("Signup enrichment is US-only; refusing to dispatch in this region")
+ # Cloud only, mirrors the signup-path region gate (posthog/temporal/signup_enrichment/trigger.py).
+ if get_instance_region() not in ("US", "EU"):
+ raise CommandError("Signup enrichment is US/EU-only; refusing to dispatch in this region")
after = self._parse_datetime(options["after"])
before = self._parse_datetime(options["before"])
diff --git a/products/growth/backend/tests/test_enrichment_backfill_command.py b/products/growth/backend/tests/test_enrichment_backfill_command.py
index 3f700a8fc3a1..c56f7ad8bad7 100644
--- a/products/growth/backend/tests/test_enrichment_backfill_command.py
+++ b/products/growth/backend/tests/test_enrichment_backfill_command.py
@@ -68,6 +68,24 @@ class TestBackfillSignupEnrichment(BaseTest):
with self.assertRaises(CommandError):
call_command("backfill_signup_enrichment", **_window())
+ def test_dispatches_in_eu(self):
+ target = self._org(email="[email protected]")
+
+ with (
+ patch(f"{_COMMAND_MODULE}.get_instance_region", return_value="EU"),
+ patch(f"{_COMMAND_MODULE}.dispatch_signup_enrichment") as dispatch,
+ ):
+ call_command("backfill_signup_enrichment", "--delay=0", **_window())
+
+ assert dispatch.call_count == 1
+ assert dispatch.call_args.args[0].organization_id == str(target.id)
+
+ def test_refuses_outside_us_and_eu(self):
+ self._org(email="[email protected]")
+ with patch(f"{_COMMAND_MODULE}.get_instance_region", return_value="DEV"):
+ with self.assertRaises(CommandError):
+ call_command("backfill_signup_enrichment", **_window())
+
def test_continues_past_a_failed_dispatch(self):
self._org(email="[email protected]")
second = self._org(email="[email protected]")
diff --git a/products/growth/backend/tests/test_enrichment_bridge.py b/products/growth/backend/tests/test_enrichment_bridge.py
index 53097cf78259..6d82cad6b59f 100644
--- a/products/growth/backend/tests/test_enrichment_bridge.py
+++ b/products/growth/backend/tests/test_enrichment_bridge.py
@@ -15,8 +15,9 @@ _ORGANIZATION_GROUP_TYPES = [{"group_type": "organization", "group_type_index":
class TestEnrichmentBridge(BaseTest):
- def _read(self, group, group_types=_ORGANIZATION_GROUP_TYPES):
+ def _read(self, group, group_types=_ORGANIZATION_GROUP_TYPES, region="US"):
with (
+ patch("products.growth.backend.enrichment.bridge.get_instance_region", return_value=region),
patch("products.growth.backend.enrichment.bridge.Team.objects.get", return_value=self.team),
patch(
"products.growth.backend.enrichment.bridge.get_group_types_for_project",
@@ -26,6 +27,13 @@ class TestEnrichmentBridge(BaseTest):
):
return read_clay_bridge_inputs(organization_id="org-1"), get_group
+ @parameterized.expand([("eu", "EU"), ("self_hosted", None)])
+ def test_non_us_regions_skip_the_lookup_entirely(self, _name, region):
+ inputs, get_group = self._read(Group(group_properties={"icp_company_type": "private"}), region=region)
+
+ assert inputs == ClayBridgeInputs()
+ get_group.assert_not_called()
+
def test_reads_clays_columns_off_the_organization_group(self):
group = Group(
group_properties={