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.

fix(data-imports): stop retrying a debugbear rum metrics 400 (#117847)

Tom Owers17b79ab83f5a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/debugbear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/debugbear.py
index f894074ec091..966ab5714e5e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/debugbear.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/debugbear.py
@@ -8,7 +8,7 @@ import orjson
import structlog
from dateutil import parser as dateutil_parser
from requests import Session
-from requests.exceptions import RequestException
+from requests.exceptions import HTTPError, RequestException
from products.warehouse_sources.backend.temporal.data_imports.sources.common.datetime_utils import (
coerce_datetime_to_utc,
@@ -261,7 +261,20 @@ def _iter_rum_metrics_for_project(
start = since or datetime.now(UTC) - timedelta(days=RUM_BACKFILL_DAYS)
params = {"groupByTime": RUM_GROUP_BY_TIME, "from": _iso(start)}
- payload = _get_json(session, f"/project/{project['id']}/rumMetrics", headers, params=params)
+ try:
+ payload = _get_json(session, f"/project/{project['id']}/rumMetrics", headers, params=params)
+ except HTTPError as exc:
+ # DebugBear's rumMetrics endpoint 400s for a project with no Real User Monitoring data
+ # rather than returning an empty series, so the request stays identical on every retry.
+ # Re-raise under a stable message so `get_non_retryable_errors` can stop the sync instead
+ # of retrying a project that will never answer.
+ if exc.response is not None and exc.response.status_code == 400:
+ raise HTTPError(
+ f"DebugBear rejected the RUM metrics request for project {project['id']} with a 400 "
+ "error — Real User Monitoring is likely not set up for this project.",
+ response=exc.response,
+ ) from exc
+ raise
yield from _flatten_rum_metrics(project_fields, payload)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/source.py
index 00b486755012..48ff50dc3cfe 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/source.py
@@ -47,6 +47,9 @@ class DebugbearSource(SimpleSource[DebugbearSourceConfig]):
return {
"401 Client Error": "Your DebugBear API key is invalid or expired. Please generate a new key and reconnect.",
"403 Client Error": "Your DebugBear API key doesn't have permission for this request. Use an Admin API key (Account settings > API Keys) and reconnect.",
+ # Raised by `_iter_rum_metrics_for_project` after DebugBear 400s on a project with no
+ # RUM data; the raw message already names the project and the likely fix.
+ "DebugBear rejected the RUM metrics request": None,
}
def get_canonical_descriptions(self) -> CanonicalDescriptions:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear.py
index 43fb3ebac249..ddec632f02db 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear.py
@@ -279,6 +279,13 @@ class TestIterRumMetricsForProject:
assert list(_iter_rum_metrics_for_project(session, {}, {}, since=None)) == []
session.get.assert_not_called()
+ def test_400_response_raises_a_stable_non_retryable_message(self) -> None:
+ session = MagicMock()
+ session.get.return_value = _response({}, status_code=400)
+
+ with pytest.raises(HTTPError, match="DebugBear rejected the RUM metrics request"):
+ list(_iter_rum_metrics_for_project(session, {}, {"id": "p1"}, since=None))
+
class TestIterRumPageViewsForProject:
def test_incremental_passes_the_watermark_as_from(self) -> None:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear_source.py
index 8e9925611fe4..8db3427d7777 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/debugbear/tests/test_debugbear_source.py
@@ -26,6 +26,11 @@ class TestDebugbearSource:
[
("401 Client Error", "401 Client Error: Unauthorized for url: https://www.debugbear.com/api/v1/projects"),
("403 Client Error", "403 Client Error: Forbidden for url: https://www.debugbear.com/api/v1/projects"),
+ (
+ "DebugBear rejected the RUM metrics request",
+ "DebugBear rejected the RUM metrics request for project 1 with a 400 error — "
+ "Real User Monitoring is likely not set up for this project.",
+ ),
],
)
def test_non_retryable_errors_match(self, pattern: str, message: str) -> None: