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(error-tracking): back ingestion_enabled with a pipeline override (#120985)

Paweł Ledwoń39acb6aa04a4
diff --git a/products/error_tracking/backend/facade/api.py b/products/error_tracking/backend/facade/api.py
index 96cbcb04ac8d..43d9084f8dfe 100644
--- a/products/error_tracking/backend/facade/api.py
+++ b/products/error_tracking/backend/facade/api.py
@@ -7,6 +7,7 @@ from datetime import datetime
from typing import Any
from uuid import UUID
+from django.db import transaction
from django.db.models import QuerySet
import posthoganalytics
@@ -198,21 +199,27 @@ def resolve_fingerprints(team_id: int, issue_ids: list[str]) -> list[str]:
return resolve_fingerprints_for_issues(team_id=team_id, issue_ids=issue_ids)
-def _to_settings(settings) -> contracts.ErrorTrackingSettings:
+def _to_settings(settings, ingestion_enabled: bool) -> contracts.ErrorTrackingSettings:
return contracts.ErrorTrackingSettings(
project_rate_limit_value=settings.project_rate_limit_value,
project_rate_limit_bucket_size_minutes=settings.project_rate_limit_bucket_size_minutes,
per_issue_rate_limit_value=settings.per_issue_rate_limit_value,
per_issue_rate_limit_bucket_size_minutes=settings.per_issue_rate_limit_bucket_size_minutes,
+ ingestion_enabled=ingestion_enabled,
)
def get_settings(team_id: int) -> contracts.ErrorTrackingSettings:
- return _to_settings(logic.get_or_create_settings(team_id))
+ return _to_settings(logic.get_or_create_settings(team_id), logic.is_exception_ingestion_enabled(team_id))
-def update_settings(team_id: int, fields: dict[str, int | None]) -> contracts.ErrorTrackingSettings:
- return _to_settings(logic.update_settings(team_id=team_id, fields=fields))
+def update_settings(team_id: int, fields: dict[str, int | bool | None]) -> contracts.ErrorTrackingSettings:
+ ingestion_enabled = fields.get("ingestion_enabled")
+ with transaction.atomic():
+ if isinstance(ingestion_enabled, bool):
+ logic.set_exception_ingestion_enabled(team_id, ingestion_enabled)
+ settings = logic.update_settings(team_id=team_id, fields=fields)
+ return _to_settings(settings, logic.is_exception_ingestion_enabled(team_id))
def _to_spike_detection_config(config) -> contracts.ErrorTrackingSpikeDetectionConfig:
diff --git a/products/error_tracking/backend/facade/contracts.py b/products/error_tracking/backend/facade/contracts.py
index 14a2939ab77c..a6bd0dc2875f 100644
--- a/products/error_tracking/backend/facade/contracts.py
+++ b/products/error_tracking/backend/facade/contracts.py
@@ -171,6 +171,7 @@ class ErrorTrackingSettings:
project_rate_limit_bucket_size_minutes: int | None
per_issue_rate_limit_value: int | None
per_issue_rate_limit_bucket_size_minutes: int | None
+ ingestion_enabled: bool
@dataclass(frozen=True)
diff --git a/products/error_tracking/backend/logic/__init__.py b/products/error_tracking/backend/logic/__init__.py
index 76cb524b08da..2b1917bd46fc 100644
--- a/products/error_tracking/backend/logic/__init__.py
+++ b/products/error_tracking/backend/logic/__init__.py
@@ -5,6 +5,8 @@ from uuid import UUID
from django.conf import settings
from django.db.models import Count, Q, QuerySet
+from posthog.models.event_filter_config import EventFilterPipelineOverride
+from posthog.models.event_ingestion_restriction_config import IngestionPipeline
from posthog.models.utils import UUIDT
from products.error_tracking.backend.models import (
@@ -227,7 +229,7 @@ def get_or_create_settings(team_id: int) -> ErrorTrackingSettings:
return settings
-def update_settings(team_id: int, fields: dict[str, int | None]) -> ErrorTrackingSettings:
+def update_settings(team_id: int, fields: dict[str, int | bool | None]) -> ErrorTrackingSettings:
settings = get_or_create_settings(team_id)
updates = {key: value for key, value in fields.items() if key in SETTINGS_FIELDS}
for key, value in updates.items():
@@ -237,6 +239,24 @@ def update_settings(team_id: int, fields: dict[str, int | None]) -> ErrorTrackin
return settings
+def is_exception_ingestion_enabled(team_id: int) -> bool:
+ drop_all_events = (
+ EventFilterPipelineOverride.objects.for_team(team_id)
+ .filter(pipeline=IngestionPipeline.ERRORTRACKING)
+ .values_list("drop_all_events", flat=True)
+ .first()
+ )
+ return not drop_all_events
+
+
+def set_exception_ingestion_enabled(team_id: int, enabled: bool) -> None:
+ EventFilterPipelineOverride.objects.for_team(team_id).update_or_create(
+ team_id=team_id,
+ pipeline=IngestionPipeline.ERRORTRACKING,
+ defaults={"drop_all_events": not enabled},
+ )
+
+
def get_or_create_spike_detection_config(team_id: int) -> ErrorTrackingSpikeDetectionConfig:
config, _ = ErrorTrackingSpikeDetectionConfig.objects.get_or_create(team_id=team_id)
return config
diff --git a/products/error_tracking/backend/presentation/views/settings.py b/products/error_tracking/backend/presentation/views/settings.py
index 5f6e8183c6b8..6b77d0ba6b9d 100644
--- a/products/error_tracking/backend/presentation/views/settings.py
+++ b/products/error_tracking/backend/presentation/views/settings.py
@@ -33,6 +33,13 @@ class ErrorTrackingSettingsSerializer(serializers.Serializer):
required=False,
help_text="Bucket window over which the per-issue rate limit applies, in minutes.",
)
+ ingestion_enabled = serializers.BooleanField(
+ required=False,
+ help_text=(
+ "Whether the project ingests exception events. When false, ingestion drops every $exception event "
+ "for this project before it is stored or billed, and the events cannot be recovered."
+ ),
+ )
class ErrorTrackingSettingsViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
diff --git a/products/error_tracking/backend/test/test_facade_api.py b/products/error_tracking/backend/test/test_facade_api.py
index fad04c296b10..4c0143aa1571 100644
--- a/products/error_tracking/backend/test/test_facade_api.py
+++ b/products/error_tracking/backend/test/test_facade_api.py
@@ -3,6 +3,7 @@ from datetime import timedelta
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.db import DataError
from django.test import override_settings
from django.utils.timezone import now
@@ -11,6 +12,8 @@ from parameterized import parameterized
from rest_framework.exceptions import ValidationError as DRFValidationError
from posthog.models import Team
+from posthog.models.event_filter_config import EventFilterPipelineOverride
+from posthog.models.event_ingestion_restriction_config import IngestionPipeline
from posthog.models.integration import GitLabIntegrationError, Integration
from products.access_control.backend.facade.testing import add_role_member, create_role
@@ -616,6 +619,26 @@ class TestErrorTrackingFacadeAPI(BaseTest):
assert api.get_settings(other_team.id).project_rate_limit_value is None
+ @parameterized.expand([("project", False), ("environment", True)])
+ def test_exception_ingestion_switch_writes_the_environment_pipeline_override(self, _name, via_environment):
+ team_id = self.team.id
+ if via_environment:
+ team_id = Team.objects.create(
+ organization=self.organization, project=self.project, parent_team=self.team, name="Environment"
+ ).id
+ assert api.get_settings(team_id).ingestion_enabled is True
+
+ for enabled in (False, True):
+ assert api.update_settings(team_id, {"ingestion_enabled": enabled}).ingestion_enabled is enabled
+ overrides = EventFilterPipelineOverride.objects.unscoped().values_list(
+ "team_id", "pipeline", "drop_all_events"
+ )
+ assert list(overrides) == [(team_id, IngestionPipeline.ERRORTRACKING, not enabled)]
+
+ with self.assertRaises(DataError):
+ api.update_settings(team_id, {"ingestion_enabled": False, "project_rate_limit_value": 2**31})
+ assert api.get_settings(team_id).ingestion_enabled is True
+
def test_spike_detection_config_get_and_update(self):
config = api.get_spike_detection_config(self.team.id)
assert isinstance(config, contracts.ErrorTrackingSpikeDetectionConfig)
diff --git a/products/error_tracking/frontend/generated/api.schemas.ts b/products/error_tracking/frontend/generated/api.schemas.ts
index 039fc2461f55..cb69fd06b773 100644
--- a/products/error_tracking/frontend/generated/api.schemas.ts
+++ b/products/error_tracking/frontend/generated/api.schemas.ts
@@ -2204,6 +2204,8 @@ export interface ErrorTrackingSettingsApi {
* @nullable
*/
per_issue_rate_limit_bucket_size_minutes?: number | null
+ /** Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered. */
+ ingestion_enabled?: boolean
}
export interface PatchedErrorTrackingSettingsApi {
@@ -2231,6 +2233,8 @@ export interface PatchedErrorTrackingSettingsApi {
* @nullable
*/
per_issue_rate_limit_bucket_size_minutes?: number | null
+ /** Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered. */
+ ingestion_enabled?: boolean
}
/**
diff --git a/products/error_tracking/frontend/generated/api.zod.ts b/products/error_tracking/frontend/generated/api.zod.ts
index 7258c349966d..44e04576624b 100644
--- a/products/error_tracking/frontend/generated/api.zod.ts
+++ b/products/error_tracking/frontend/generated/api.zod.ts
@@ -1105,6 +1105,12 @@ export const ErrorTrackingSettingsUpdateSettingsPartialUpdateBody = /* @__PURE__
.min(1)
.nullish()
.describe('Bucket window over which the per-issue rate limit applies, in minutes.'),
+ ingestion_enabled: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered.'
+ ),
})
export const errorTrackingSeverityRulesCreateBodyOrderKeyDefault = 0
diff --git a/products/error_tracking/mcp/tools.yaml b/products/error_tracking/mcp/tools.yaml
index 88ce1bc8517b..395c61671404 100644
--- a/products/error_tracking/mcp/tools.yaml
+++ b/products/error_tracking/mcp/tools.yaml
@@ -274,8 +274,9 @@ tools:
idempotent: true
title: Get error tracking settings
description: >
- Get the error tracking ingestion settings for the current project. Returns the project-wide and per-issue
- exception rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each
+ Get the error tracking ingestion settings for the current project. Returns `ingestion_enabled`, which is
+ false when ingestion drops every exception the project sends, and the project-wide and per-issue exception
+ rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each
`*_rate_limit_bucket_size_minutes` is the bucket window. A null `*_rate_limit_value` means no limit is set.
Read these before updating so you can preserve the fields you don't intend to change.
error-tracking-settings-update:
@@ -295,7 +296,9 @@ tools:
limit (`per_issue_rate_limit_value` events per `per_issue_rate_limit_bucket_size_minutes`). Set a
`*_rate_limit_value` to null to remove that limit. WARNING: exception events above a rate limit are dropped
at ingestion and cannot be recovered. Lowering a limit silently discards volume — confirm the threshold with
- the user before reducing it.
+ the user before reducing it. Setting `ingestion_enabled` to false drops every exception the project sends,
+ within about a minute, until it is set back to true. Only change it when the user explicitly asks to stop or
+ resume exception ingestion.
error-tracking-severity-rules-create:
operation: error_tracking_severity_rules_create
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index fe6ff27c5943..ff8f729bf26b 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5359,7 +5359,7 @@
"system_prompt_hint": "Error tracking setup recommendations and how to act on each (error-tracking category)"
},
"error-tracking-settings-get": {
- "description": "Get the error tracking ingestion settings for the current project. Returns the project-wide and per-issue exception rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each `*_rate_limit_bucket_size_minutes` is the bucket window. A null `*_rate_limit_value` means no limit is set. Read these before updating so you can preserve the fields you don't intend to change.",
+ "description": "Get the error tracking ingestion settings for the current project. Returns `ingestion_enabled`, which is false when ingestion drops every exception the project sends, and the project-wide and per-issue exception rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each `*_rate_limit_bucket_size_minutes` is the bucket window. A null `*_rate_limit_value` means no limit is set. Read these before updating so you can preserve the fields you don't intend to change.",
"category": "Error tracking",
"feature": "error_tracking",
"summary": "Get error tracking settings",
@@ -5374,7 +5374,7 @@
}
},
"error-tracking-settings-update": {
- "description": "Update the error tracking ingestion settings for the current project. Only the fields you include are applied; omitted fields keep their existing values. Use this to set the project-wide rate limit (`project_rate_limit_value` events per `project_rate_limit_bucket_size_minutes`) and the per-issue rate limit (`per_issue_rate_limit_value` events per `per_issue_rate_limit_bucket_size_minutes`). Set a `*_rate_limit_value` to null to remove that limit. WARNING: exception events above a rate limit are dropped at ingestion and cannot be recovered. Lowering a limit silently discards volume — confirm the threshold with the user before reducing it.",
+ "description": "Update the error tracking ingestion settings for the current project. Only the fields you include are applied; omitted fields keep their existing values. Use this to set the project-wide rate limit (`project_rate_limit_value` events per `project_rate_limit_bucket_size_minutes`) and the per-issue rate limit (`per_issue_rate_limit_value` events per `per_issue_rate_limit_bucket_size_minutes`). Set a `*_rate_limit_value` to null to remove that limit. WARNING: exception events above a rate limit are dropped at ingestion and cannot be recovered. Lowering a limit silently discards volume — confirm the threshold with the user before reducing it. Setting `ingestion_enabled` to false drops every exception the project sends, within about a minute, until it is set back to true. Only change it when the user explicitly asks to stop or resume exception ingestion.",
"category": "Error tracking",
"feature": "error_tracking",
"summary": "Update error tracking settings",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index dc508bfda9dd..f8cf424d1771 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5388,7 +5388,7 @@
"system_prompt_hint": "Error tracking setup recommendations and how to act on each (error-tracking category)"
},
"error-tracking-settings-get": {
- "description": "Get the error tracking ingestion settings for the current project. Returns the project-wide and per-issue exception rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each `*_rate_limit_bucket_size_minutes` is the bucket window. A null `*_rate_limit_value` means no limit is set. Read these before updating so you can preserve the fields you don't intend to change.",
+ "description": "Get the error tracking ingestion settings for the current project. Returns `ingestion_enabled`, which is false when ingestion drops every exception the project sends, and the project-wide and per-issue exception rate limits, where each `*_rate_limit_value` is the maximum events ingested per bucket and each `*_rate_limit_bucket_size_minutes` is the bucket window. A null `*_rate_limit_value` means no limit is set. Read these before updating so you can preserve the fields you don't intend to change.",
"category": "Error tracking",
"feature": "error_tracking",
"summary": "Get error tracking settings",
@@ -5403,7 +5403,7 @@
}
},
"error-tracking-settings-update": {
- "description": "Update the error tracking ingestion settings for the current project. Only the fields you include are applied; omitted fields keep their existing values. Use this to set the project-wide rate limit (`project_rate_limit_value` events per `project_rate_limit_bucket_size_minutes`) and the per-issue rate limit (`per_issue_rate_limit_value` events per `per_issue_rate_limit_bucket_size_minutes`). Set a `*_rate_limit_value` to null to remove that limit. WARNING: exception events above a rate limit are dropped at ingestion and cannot be recovered. Lowering a limit silently discards volume — confirm the threshold with the user before reducing it.",
+ "description": "Update the error tracking ingestion settings for the current project. Only the fields you include are applied; omitted fields keep their existing values. Use this to set the project-wide rate limit (`project_rate_limit_value` events per `project_rate_limit_bucket_size_minutes`) and the per-issue rate limit (`per_issue_rate_limit_value` events per `per_issue_rate_limit_bucket_size_minutes`). Set a `*_rate_limit_value` to null to remove that limit. WARNING: exception events above a rate limit are dropped at ingestion and cannot be recovered. Lowering a limit silently discards volume — confirm the threshold with the user before reducing it. Setting `ingestion_enabled` to false drops every exception the project sends, within about a minute, until it is set back to true. Only change it when the user explicitly asks to stop or resume exception ingestion.",
"category": "Error tracking",
"feature": "error_tracking",
"summary": "Update error tracking settings",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 79bd7c53789f..1d2820c6d20f 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -44046,6 +44046,8 @@ export namespace Schemas {
* @nullable
*/
per_issue_rate_limit_bucket_size_minutes?: number | null;
+ /** Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered. */
+ ingestion_enabled?: boolean;
}
/**
@@ -85813,6 +85815,8 @@ export namespace Schemas {
* @nullable
*/
per_issue_rate_limit_bucket_size_minutes?: number | null;
+ /** Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered. */
+ ingestion_enabled?: boolean;
}
/**
diff --git a/services/mcp/src/generated/error_tracking/api.ts b/services/mcp/src/generated/error_tracking/api.ts
index 1f5541f8c37c..f094d11028d2 100644
--- a/services/mcp/src/generated/error_tracking/api.ts
+++ b/services/mcp/src/generated/error_tracking/api.ts
@@ -8809,6 +8809,12 @@ export const ErrorTrackingSettingsUpdateSettingsPartialUpdateBody = () => zod.ob
.min(1)
.nullish()
.describe('Bucket window over which the per-issue rate limit applies, in minutes.'),
+ ingestion_enabled: zod
+ .boolean()
+ .optional()
+ .describe(
+ 'Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered.'
+ ),
})
export const ErrorTrackingSeverityRulesListParams = () => zod.object({
diff --git a/services/mcp/src/tools/generated/error_tracking.ts b/services/mcp/src/tools/generated/error_tracking.ts
index a06434bf76e0..b268e2a565a1 100644
--- a/services/mcp/src/tools/generated/error_tracking.ts
+++ b/services/mcp/src/tools/generated/error_tracking.ts
@@ -461,6 +461,9 @@ const errorTrackingSettingsUpdate = (): ToolBase<
if (params.per_issue_rate_limit_bucket_size_minutes !== undefined) {
body['per_issue_rate_limit_bucket_size_minutes'] = params.per_issue_rate_limit_bucket_size_minutes
}
+ if (params.ingestion_enabled !== undefined) {
+ body['ingestion_enabled'] = params.ingestion_enabled
+ }
const result = await context.api.request<Schemas.ErrorTrackingSettings>({
method: 'PATCH',
path: `/api/projects/${encodeURIComponent(String(projectId))}/error_tracking/settings/update_settings/`,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-settings-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-settings-update.json
index 669429c7cd51..cee30434d60c 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-settings-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/error-tracking-settings-update.json
@@ -1,6 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
+ "ingestion_enabled": {
+ "description": "Whether the project ingests exception events. When false, ingestion drops every $exception event for this project before it is stored or billed, and the events cannot be recovered.",
+ "type": "boolean"
+ },
"per_issue_rate_limit_bucket_size_minutes": {
"anyOf": [
{