: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(cdp): move internal events into products/cdp (#115435)
Harley Alexander1cc507b16c73
diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.pyindex 9062402a8ad0..8d398ac9be3e 100644--- a/posthog/api/test/test_integration.py+++ b/posthog/api/test/test_integration.py@@ -7919,7 +7919,7 @@ class TestGitHubDiscoveryAudit(APIBaseTest):refreshed = self.client.get(f"/api/projects/{target.id}/integrations/github/available_installations/")assert refreshed.json()["installations"] == []- @patch("posthog.cdp.internal_events.produce_internal_event")+ @patch("products.cdp.backend.internal_events.produce_internal_event")def test_invalid_credential_discard_is_private_and_retained(self, produce: MagicMock) -> None:integration = UserIntegration.objects.create(user=self.user,diff --git a/posthog/cdp/workflow_step_resume.py b/posthog/cdp/workflow_step_resume.pyindex 8f0b7a9208f6..a903263ed715 100644--- a/posthog/cdp/workflow_step_resume.py+++ b/posthog/cdp/workflow_step_resume.py@@ -5,9 +5,10 @@ from typing import Any, Literalimport requestsimport structlog-from posthog.cdp.internal_events import WORKFLOW_STEP_RESUME_EVENT, InternalEventEvent, produce_internal_eventfrom posthog.plugins.plugin_server_api import WORKFLOWS_STEP_RESUME_JWT_PURPOSE, resume_workflow_step+from products.cdp.backend.internal_events import WORKFLOW_STEP_RESUME_EVENT, InternalEventEvent, produce_internal_event+logger = structlog.get_logger(__name__)RESULT_STRING_CAP = 1500diff --git a/posthog/models/activity_logging/activity_log.py b/posthog/models/activity_logging/activity_log.pyindex eda104ff2af6..b08e14e50191 100644--- a/posthog/models/activity_logging/activity_log.py+++ b/posthog/models/activity_logging/activity_log.py@@ -1725,9 +1725,10 @@ def bound_detail_for_internal_event(detail: Any) -> tuple[Any, bool]:def activity_log_created(sender, instance: "ActivityLog", created, **kwargs):from posthog.api.advanced_activity_logs import ActivityLogSerializerfrom posthog.api.shared import UserBasicSerializer- from posthog.cdp.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom posthog.models.activity_logging.utils import activity_visibility_manager+ from products.cdp.backend.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_event+if not created:returndiff --git a/posthog/models/comment/utils.py b/posthog/models/comment/utils.pyindex d92dc13bab82..85b0533db85f 100644--- a/posthog/models/comment/utils.py+++ b/posthog/models/comment/utils.py@@ -5,11 +5,12 @@ from django.conf import settingsimport structlog-from posthog.cdp.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models import Userfrom posthog.models.comment.comment import CANVAS_COMMENT_SCOPES+from products.cdp.backend.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_event+if TYPE_CHECKING:from posthog.models.comment import Commentdiff --git a/posthog/tasks/activity_log.py b/posthog/tasks/activity_log.pyindex 2e213929a914..98776c42739d 100644--- a/posthog/tasks/activity_log.py+++ b/posthog/tasks/activity_log.py@@ -1,10 +1,11 @@import structlogfrom celery import shared_task-from posthog.cdp.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom posthog.models import Teamfrom posthog.scoping_audit import skip_team_scope_audit+from products.cdp.backend.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_event+logger = structlog.get_logger(__name__)diff --git a/posthog/temporal/experiments/utils.py b/posthog/temporal/experiments/utils.pyindex 7fc4d1b5f442..249b7d7b738d 100644--- a/posthog/temporal/experiments/utils.py+++ b/posthog/temporal/experiments/utils.py@@ -4,8 +4,7 @@ from django.db.models import Qimport structlog-from posthog.cdp.internal_events import InternalEventEvent, produce_internal_event-+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_eventfrom products.experiments.backend.facade.timeseries import apply_saved_metric_overridesfrom products.experiments.backend.models.experiment import (Experiment,diff --git a/posthog/temporal/health_checks/alerts.py b/posthog/temporal/health_checks/alerts.pyindex 53205e6f3a20..39e66fdfc984 100644--- a/posthog/temporal/health_checks/alerts.py+++ b/posthog/temporal/health_checks/alerts.py@@ -2,7 +2,6 @@ from typing import Literalimport structlog-from posthog.cdp.internal_events import InternalEventEvent, produce_internal_eventfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models.health_issue import HealthIssuefrom posthog.temporal.health_checks.framework import (@@ -12,6 +11,8 @@ from posthog.temporal.health_checks.framework import (remediation_for_kind,)+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_event+logger = structlog.get_logger(__name__)diff --git a/posthog/test/activity_logging/test_activity_logging.py b/posthog/test/activity_logging/test_activity_logging.pyindex 8e74f4d207d0..19dee683009a 100644--- a/posthog/test/activity_logging/test_activity_logging.py+++ b/posthog/test/activity_logging/test_activity_logging.py@@ -116,7 +116,7 @@ class TestActivityLogModel(BaseTest):def test_internal_event_detail_stays_under_kafka_limit(self, _name: str, after: str, truncated: bool) -> None:change = Change(type="FeatureFlag", field="filters", action="changed", before=None, after=after)with (- patch("posthog.cdp.internal_events.produce_internal_event") as mock_produce,+ patch("products.cdp.backend.internal_events.produce_internal_event") as mock_produce,self.captureOnCommitCallbacks(execute=True),):log_activity(diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 9392d362ce15..19f6b831d682 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -1417,7 +1417,7 @@3 ee/clickhouse/views/test/test_clickhouse_trends.py3 posthog/api/app_metrics2.py3 posthog/api/test/rust_integration/conftest.py-3 posthog/cdp/internal_events.py+3 products/cdp/backend/internal_events.py3 posthog/dags/backups.py3 posthog/hogql/compiler/bytecode.py3 products/product_analytics/backend/hogql_queries/trends/test/test_trends_query_runner.pydiff --git a/products/alerts/backend/facade/contracts.py b/products/alerts/backend/facade/contracts.pyindex f3f08681e241..ecb298c6b9d3 100644--- a/products/alerts/backend/facade/contracts.py+++ b/products/alerts/backend/facade/contracts.py@@ -9,9 +9,8 @@ from __future__ import annotationsfrom typing import Final-from posthog.cdp.internal_events import LEGACY_INSIGHT_ALERT_EVENT-from products.alerts_platform.backend.facade.contracts import DestinationType+from products.cdp.backend.internal_events import LEGACY_INSIGHT_ALERT_EVENT# The internal event an insight alert's destinations fire on. Do not take it from# `posthog.tasks.alerts.utils` instead, because that module imports this product's facade.diff --git a/products/alerts/backend/logic/alert_email.py b/products/alerts/backend/logic/alert_email.pyindex af2f9f7cf40a..c5f50873f383 100644--- a/products/alerts/backend/logic/alert_email.py+++ b/products/alerts/backend/logic/alert_email.py@@ -10,8 +10,6 @@ from collections.abc import Collectionfrom typing import Finalfrom uuid import UUID-from posthog.cdp.internal_events import LEGACY_INSIGHT_ALERT_EVENT-from products.access_control.backend.facade.user_access_control import UserAccessControlfrom products.alerts.backend.logic.destinations import list_alert_destination_groupsfrom products.alerts.backend.models.alert import AlertConfiguration@@ -20,6 +18,7 @@ from products.alerts_platform.backend.facade.contracts import (AlertDestinationGroup,DestinationType,)+from products.cdp.backend.internal_events import LEGACY_INSIGHT_ALERT_EVENT# A failed check has no internal event of its own, because production emails it directly. The# platform routes errored transitions to email by this id, which no HogFunction can subscribe to.diff --git a/products/alerts/backend/logic/destinations.py b/products/alerts/backend/logic/destinations.pyindex d74c83fdaae5..9c19358b2916 100644--- a/products/alerts/backend/logic/destinations.py+++ b/products/alerts/backend/logic/destinations.py@@ -15,7 +15,6 @@ import structlogimport posthoganalyticsfrom prometheus_client import Counter-from posthog.cdp.internal_events import InternalEventEvent, flush_internal_events_producer, produce_internal_eventfrom posthog.exceptions_capture import capture_exceptionfrom posthog.kafka_client.client import ProduceResultfrom posthog.plugins.plugin_server_api import reload_hog_functions_on_workers@@ -31,6 +30,11 @@ from products.alerts_platform.backend.facade.contracts import ()from products.cdp.backend.facade.api import create_hog_functionsfrom products.cdp.backend.facade.models import HogFunction+from products.cdp.backend.internal_events import (+ InternalEventEvent,+ flush_internal_events_producer,+ produce_internal_event,+)logger = structlog.get_logger(__name__)diff --git a/products/alerts/backend/logic/insight_alert_destinations.py b/products/alerts/backend/logic/insight_alert_destinations.pyindex ad16fa52a570..29a50572db14 100644--- a/products/alerts/backend/logic/insight_alert_destinations.py+++ b/products/alerts/backend/logic/insight_alert_destinations.py@@ -10,8 +10,6 @@ from __future__ import annotationsfrom typing import Any, Final-from posthog.cdp.internal_events import LEGACY_INSIGHT_ALERT_EVENT-from products.alerts.backend.logic.destination_configs import (DESTINATION_SPECS,clip_hog_function_name,@@ -22,6 +20,7 @@ from products.alerts_platform.backend.facade.contracts import (AlertDestinationData,DestinationType,)+from products.cdp.backend.internal_events import LEGACY_INSIGHT_ALERT_EVENTSLACK_TEMPLATE_ID: Final = DESTINATION_SPECS[DestinationType.SLACK].template_iddiff --git a/products/alerts/backend/platform_source_cycle.py b/products/alerts/backend/platform_source_cycle.pyindex 34fc4e8e8849..9f66a3fcb9db 100644--- a/products/alerts/backend/platform_source_cycle.py+++ b/products/alerts/backend/platform_source_cycle.py@@ -24,7 +24,6 @@ from django.conf import settingsimport structlog-from posthog.cdp.internal_events import LEGACY_INSIGHT_ALERT_EVENTfrom posthog.clickhouse.client.connection import ClickHouseUserfrom posthog.clickhouse.query_tagging import Feature, Product, tag_queriesfrom posthog.errors import CH_TRANSIENT_ERRORS, QueryErrorCategory, classify_query_error@@ -68,6 +67,7 @@ from products.alerts_platform.backend.facade.platform_metrics import (record_scheduler_lag,safe_record,)+from products.cdp.backend.internal_events import LEGACY_INSIGHT_ALERT_EVENTlogger = structlog.get_logger(__name__)diff --git a/products/alerts/backend/test/test_alert_email.py b/products/alerts/backend/test/test_alert_email.pyindex c766eb44c431..90b378d80ec5 100644--- a/products/alerts/backend/test/test_alert_email.py+++ b/products/alerts/backend/test/test_alert_email.py@@ -2,7 +2,6 @@ from posthog.test.base import APIBaseTestfrom parameterized import parameterized-from posthog.cdp.internal_events import LEGACY_INSIGHT_ALERT_EVENTfrom posthog.models.user import Userfrom products.alerts.backend.facade.destinations import list_alert_destination_groups, list_delivery_destination_groups@@ -10,6 +9,7 @@ from products.alerts.backend.logic.alert_email import INSIGHT_ALERT_ERRORED_EVENfrom products.alerts.backend.models.alert import AlertConfiguration, AlertSubscriptionfrom products.alerts.backend.test.insight_alerts import create_insight_alertfrom products.alerts_platform.backend.facade.contracts import DestinationType+from products.cdp.backend.internal_events import LEGACY_INSIGHT_ALERT_EVENTclass TestInsightAlertEmailDestination(APIBaseTest):diff --git a/products/batch_exports/backend/temporal/batch_exports.py b/products/batch_exports/backend/temporal/batch_exports.pyindex 84b385339464..805d24c19b51 100644--- a/products/batch_exports/backend/temporal/batch_exports.py+++ b/products/batch_exports/backend/temporal/batch_exports.py@@ -14,7 +14,6 @@ from structlog.contextvars import bind_contextvarsfrom temporalio import activity, exceptions, workflowfrom temporalio.common import RetryPolicy-from posthog.cdp.internal_events import InternalEventEvent, create_internal_event, internal_event_to_dictfrom posthog.kafka_client.routing import async_producer_scopefrom posthog.kafka_client.topics import KAFKA_APP_METRICS2, KAFKA_CDP_INTERNAL_EVENTSfrom posthog.models.team.team import Team@@ -52,6 +51,7 @@ from products.batch_exports.backend.temporal.sql.events import (SELECT_FROM_EVENTS_VIEW_UNBOUNDED,native_events_export_query,)+from products.cdp.backend.internal_events import InternalEventEvent, create_internal_event, internal_event_to_dictfrom products.notifications.backend.facade.api import (NotificationData,NotificationType,diff --git a/products/cdp/backend/api/hog_function.py b/products/cdp/backend/api/hog_function.pyindex 7d7b91c1382c..252b1f32b051 100644--- a/products/cdp/backend/api/hog_function.py+++ b/products/cdp/backend/api/hog_function.py@@ -29,11 +29,6 @@ from posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializerfrom posthog.api.utils import action, log_activity_from_viewsetfrom posthog.cdp.filters import DATA_WAREHOUSE_SOURCES-from posthog.cdp.internal_events import (- generic_api_editable_alert_scope,- is_managed_alert_internal_event,- is_reserved_internal_event,-)from posthog.cdp.services.icons import CDPIconsServicefrom posthog.cdp.site_functions import get_transpiled_functionfrom posthog.cdp.validation import (@@ -66,6 +61,11 @@ from posthog.scopes import APIScopeObjectfrom products.batch_exports.backend.facade import api as batch_exports_apifrom products.batch_exports.backend.facade.contracts import InvalidBatchExportFiltersfrom products.cdp.backend.api.hog_function_template import HogFunctionTemplateSerializer+from products.cdp.backend.internal_events import (+ generic_api_editable_alert_scope,+ is_managed_alert_internal_event,+ is_reserved_internal_event,+)from products.cdp.backend.models.hog_function_template import HogFunctionTemplatefrom products.cdp.backend.models.hog_functions.hog_function import (TYPES_THAT_CAN_RERUN,diff --git a/posthog/cdp/internal_events.py b/products/cdp/backend/internal_events.pysimilarity index 100%rename from posthog/cdp/internal_events.pyrename to products/cdp/backend/internal_events.pydiff --git a/products/data_warehouse/backend/logic/external_data_source/alerts.py b/products/data_warehouse/backend/logic/external_data_source/alerts.pyindex aeba6c396ec5..dc440b6ff0b2 100644--- a/products/data_warehouse/backend/logic/external_data_source/alerts.py+++ b/products/data_warehouse/backend/logic/external_data_source/alerts.py@@ -8,10 +8,10 @@ from django.core.cache import cacheimport structlogfrom prometheus_client import Counter-from posthog.cdp.internal_events import InternalEventEvent, produce_internal_eventfrom posthog.exceptions_capture import capture_exceptionfrom products.cdp.backend.facade.models import HogFunction+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_eventfrom products.warehouse_sources.backend.facade.api import get_sync_alert_contextfrom products.warehouse_sources.backend.facade.types import ExternalDataJobStatus, ExternalDataSchemaStatusdiff --git a/products/early_access_features/backend/api.py b/products/early_access_features/backend/api.pyindex ec37842c1a4c..9f9f403469d1 100644--- a/products/early_access_features/backend/api.py+++ b/products/early_access_features/backend/api.py@@ -15,7 +15,6 @@ from rest_framework.response import Responsefrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializerfrom posthog.api.utils import get_token-from posthog.cdp.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom posthog.exceptions import generate_exception_responsefrom posthog.models.organization import OrganizationMembershipfrom posthog.models.team.team import Team@@ -29,6 +28,7 @@ from products.access_control.backend.presentation.access_control import (AccessControlViewSetMixin,UserAccessControlSerializerMixin,)+from products.cdp.backend.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom products.feature_flags.backend.api.feature_flag import (MinimalFeatureFlagSerializer,assert_feature_flag_write_scope,diff --git a/products/error_tracking/backend/logic/lifecycle_events.py b/products/error_tracking/backend/logic/lifecycle_events.pyindex 9fb5e1979d82..84edb693e2c4 100644--- a/products/error_tracking/backend/logic/lifecycle_events.py+++ b/products/error_tracking/backend/logic/lifecycle_events.py@@ -14,9 +14,9 @@ from django.db import transactionimport structlog-from posthog.cdp.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom posthog.models.user import User+from products.cdp.backend.internal_events import InternalEventEvent, InternalEventPerson, produce_internal_eventfrom products.error_tracking.backend.logic.assignees import resolve_current_assigneefrom products.error_tracking.backend.models import (ErrorTrackingAlert,diff --git a/products/error_tracking/backend/temporal/lifecycle/side_effects.py b/products/error_tracking/backend/temporal/lifecycle/side_effects.pyindex d5d945efe676..54b0a834ff74 100644--- a/products/error_tracking/backend/temporal/lifecycle/side_effects.py+++ b/products/error_tracking/backend/temporal/lifecycle/side_effects.py@@ -6,7 +6,6 @@ from django.utils.dateparse import parse_datetimefrom asgiref.sync import sync_to_asyncfrom confluent_kafka import KafkaError, KafkaException-from posthog.cdp.internal_events import InternalEventEvent, flush_internal_events_producer, produce_internal_eventfrom posthog.helpers.tiktoken_encoding import (LLM_TOKEN_COUNT_PROXY_MODEL,TEXT_EMBEDDING_3_TOKEN_COUNT_PROXY_MODEL,@@ -14,6 +13,11 @@ from posthog.helpers.tiktoken_encoding import ()from posthog.models import Team+from products.cdp.backend.internal_events import (+ InternalEventEvent,+ flush_internal_events_producer,+ produce_internal_event,+)from products.error_tracking.backend.logic.assignees import resolve_current_assigneefrom products.error_tracking.backend.temporal.alerts.dispatch import start_alert_delivery_workflowfrom products.error_tracking.backend.temporal.alerts.types import AlertDeliveryWorkflowInputsdiff --git a/products/error_tracking/backend/temporal/lifecycle/test/test_side_effects.py b/products/error_tracking/backend/temporal/lifecycle/test/test_side_effects.pyindex fb9da964a9b5..601c67fe9670 100644--- a/products/error_tracking/backend/temporal/lifecycle/test/test_side_effects.py+++ b/products/error_tracking/backend/temporal/lifecycle/test/test_side_effects.py@@ -6,9 +6,9 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom confluent_kafka import KafkaError, KafkaException-from posthog.cdp.internal_events import InternalEventEventfrom posthog.helpers.tiktoken_encoding import LLM_TOKEN_COUNT_PROXY_MODEL, get_tiktoken_encoding_for_model+from products.cdp.backend.internal_events import InternalEventEventfrom products.error_tracking.backend.logic.assignees import ResolvedAssigneefrom products.error_tracking.backend.temporal.lifecycle.issue_created.types import (IssueCreatedSnapshot,diff --git a/products/replay_vision/backend/observation_requests.py b/products/replay_vision/backend/observation_requests.pyindex 331b5d95ea09..d38cd243a67f 100644--- a/products/replay_vision/backend/observation_requests.py+++ b/products/replay_vision/backend/observation_requests.py@@ -17,7 +17,6 @@ from django.utils import timezoneimport structlog-from posthog.cdp.internal_events import InternalEventEvent, flush_internal_events_producer, produce_internal_eventfrom posthog.dataclasses import frozenfrom posthog.kafka_client.client import ProduceResultfrom posthog.models.organization import OrganizationMembership@@ -26,6 +25,11 @@ from posthog.models.user import Userfrom posthog.slack.formatting import escape_slack_mrkdwnfrom products.access_control.backend.facade.user_access_control import UserAccessControl+from products.cdp.backend.internal_events import (+ InternalEventEvent,+ flush_internal_events_producer,+ produce_internal_event,+)from products.replay_vision.backend.distinct_ids import replay_vision_distinct_idfrom products.replay_vision.backend.models.replay_observation import TERMINAL_STATUSES, ReplayObservationfrom products.replay_vision.backend.models.replay_observation_request import (diff --git a/products/slack_app/backend/slack_workflow_events.py b/products/slack_app/backend/slack_workflow_events.pyindex fefff6290f9d..c7ce46213439 100644--- a/products/slack_app/backend/slack_workflow_events.py+++ b/products/slack_app/backend/slack_workflow_events.py@@ -10,9 +10,10 @@ from typing import Anyimport structlog-from posthog.cdp.internal_events import InternalEventEvent, produce_internal_eventfrom posthog.models.integration import Integration+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_event+logger = structlog.get_logger(__name__)SLACK_MESSAGE_RECEIVED_EVENT = "$slack_message_received"diff --git a/products/workflows/backend/github_workflow_events.py b/products/workflows/backend/github_workflow_events.pyindex 25b3101b2e55..ec0457337290 100644--- a/products/workflows/backend/github_workflow_events.py+++ b/products/workflows/backend/github_workflow_events.py@@ -17,11 +17,12 @@ from django.conf import settingsimport structlog-from posthog.cdp.internal_events import InternalEventEvent, produce_internal_eventfrom posthog.ingress.dispatch.database import bounded_statement_timeout, is_statement_timeoutfrom posthog.models.instance_setting import get_instance_settingfrom posthog.models.integration import Integration+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_event+logger = structlog.get_logger(__name__)GITHUB_EVENT_RECEIVED_EVENT = "$github_event_received"diff --git a/tach.toml b/tach.tomlindex 9394d5cd60c5..dda7e99cf869 100644--- a/tach.toml+++ b/tach.toml@@ -244,6 +244,8 @@ depends_on = ["posthog","products.access_control","products.notifications",+ # Batch export runs emit internal events through products.cdp.backend.internal_events.+ "products.cdp",]layer = "modules"@@ -429,6 +431,8 @@ depends_on = ["posthog","ee","products.feature_flags", "products.access_control",+ # Enrollment changes emit internal events through products.cdp.backend.internal_events.+ "products.cdp",]layer = "modules"@@ -925,6 +929,8 @@ depends_on = ["products.product_analytics","products.signals","products.tasks", "products.access_control",+ # Slack triggers emit internal events through products.cdp.backend.internal_events.+ "products.cdp",]layer = "modules"