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-warehouse): treat microsoft clarity 5xx as retryable (#119281)

Tom Owersb3583eeee6f7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/source.py
index c8675cdf74f1..b0811affeeea 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/source.py
@@ -24,6 +24,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
MicrosoftClaritySourceConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.microsoft_clarity.microsoft_clarity import (
+ BASE_URL,
+ INSIGHTS_PATH,
TOKEN_INVALID_ERROR,
TOKEN_WRONG_PROJECT_ERROR,
microsoft_clarity_source,
@@ -80,7 +82,19 @@ class MicrosoftClaritySource(SimpleSource[MicrosoftClaritySourceConfig]):
# re-raising once that budget is exhausted. urllib3 wraps that as "... Max retries exceeded
# with url: ..." regardless of the underlying cause. Temporal then retries the whole
# activity, so the failure is transient and self-recovering, not a bug to report.
- return {"Max retries exceeded with url"}
+ #
+ # `microsoft_clarity_source` also calls `response.raise_for_status()` directly rather than
+ # through the shared REST engine, so a 5xx that survives `DEFAULT_RETRY`'s in-process
+ # retries isn't wrapped as RESTClientRetryableError either — it's still a transient Clarity
+ # outage. Match status, reason and the endpoint's base URL, not the query string, since
+ # numOfDays/dimension vary per sync.
+ return {
+ "Max retries exceeded with url",
+ f"500 Server Error: Internal Server Error for url: {BASE_URL}{INSIGHTS_PATH}",
+ f"502 Server Error: Bad Gateway for url: {BASE_URL}{INSIGHTS_PATH}",
+ f"503 Server Error: Service Unavailable for url: {BASE_URL}{INSIGHTS_PATH}",
+ f"504 Server Error: Gateway Timeout for url: {BASE_URL}{INSIGHTS_PATH}",
+ }
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.backend.temporal.data_imports.sources.microsoft_clarity.canonical_descriptions import (
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/tests/test_microsoft_clarity_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/tests/test_microsoft_clarity_source.py
index 1ab4be02ca95..413f3b2bb99a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/tests/test_microsoft_clarity_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/microsoft_clarity/tests/test_microsoft_clarity_source.py
@@ -5,6 +5,7 @@ from unittest.mock import MagicMock
from parameterized import parameterized
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matches
from products.warehouse_sources.backend.temporal.data_imports.sources.microsoft_clarity import source as source_module
from products.warehouse_sources.backend.temporal.data_imports.sources.microsoft_clarity.settings import (
ENDPOINT_NAME,
@@ -69,6 +70,49 @@ class TestNonRetryableErrors:
)
assert any(pattern in error_msg for pattern in MicrosoftClaritySource().get_retryable_errors())
+ @parameterized.expand(
+ [
+ (
+ "server_error",
+ "500 Server Error: Internal Server Error for url: "
+ "https://www.clarity.ms/export-data/api/v1/project-live-insights?numOfDays=1",
+ True,
+ ),
+ (
+ "bad_gateway",
+ "502 Server Error: Bad Gateway for url: "
+ "https://www.clarity.ms/export-data/api/v1/project-live-insights?numOfDays=3&dimension1=OS",
+ True,
+ ),
+ (
+ "service_unavailable",
+ "503 Server Error: Service Unavailable for url: "
+ "https://www.clarity.ms/export-data/api/v1/project-live-insights",
+ True,
+ ),
+ (
+ "gateway_timeout",
+ "504 Server Error: Gateway Timeout for url: "
+ "https://www.clarity.ms/export-data/api/v1/project-live-insights",
+ True,
+ ),
+ (
+ "different_host",
+ "500 Server Error: Internal Server Error for url: https://example.com/export-data/api/v1/project-live-insights",
+ False,
+ ),
+ (
+ "client_error",
+ "400 Client Error: Bad Request for url: https://www.clarity.ms/export-data/api/v1/project-live-insights",
+ False,
+ ),
+ ]
+ )
+ def test_get_retryable_errors_match_only_clarity_server_errors(
+ self, _name: str, error_msg: str, retryable: bool
+ ) -> None:
+ assert error_message_matches(error_msg, MicrosoftClaritySource().get_retryable_errors()) is retryable
+
class TestSourceForPipeline:
def test_plumbs_config_into_transport(self, monkeypatch: Any) -> None: