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(genesys_cloud): retry transient 5xx on analytics POST queries (#129806)

Tom Owers5c631f0b7b8d
diff --git a/products/warehouse_sources/sources/genesys_cloud/genesys_cloud.py b/products/warehouse_sources/sources/genesys_cloud/genesys_cloud.py
index 10585f537cb7..51f2d1c72c18 100644
--- a/products/warehouse_sources/sources/genesys_cloud/genesys_cloud.py
+++ b/products/warehouse_sources/sources/genesys_cloud/genesys_cloud.py
@@ -14,6 +14,7 @@ from products.warehouse_sources.sources.genesys_cloud.settings import (
GenesysCloudEndpointConfig,
)
from products.warehouse_sources.sources.sdk import (
+ DEFAULT_RETRY,
OAuth2Auth,
OAuth2AuthRequestError,
ResumableSourceManager,
@@ -27,6 +28,12 @@ logger = structlog.get_logger(__name__)
REQUEST_TIMEOUT_SECONDS = 60
VALIDATION_TIMEOUT_SECONDS = 10
+# The analytics and user-analytics endpoints are queried via POST, but the body only carries the
+# interval/paging to read, not a mutation. DEFAULT_RETRY excludes POST from `allowed_methods`, so a
+# transient 429/5xx on these calls would otherwise fail the sync outright instead of retrying like
+# the listing/scan endpoints' GETs do in the same session.
+_GENESYS_CLOUD_RETRY = DEFAULT_RETRY.new(allowed_methods=frozenset(DEFAULT_RETRY.allowed_methods or ()) | {"POST"})
+
# History read on the first sync and on every full refresh.
INITIAL_HISTORY = timedelta(days=365)
ANALYTICS_WINDOW = timedelta(days=1)
@@ -70,7 +77,7 @@ def _make_auth(region: str, client_id: str, client_secret: str) -> OAuth2Auth:
def _make_session(region: str, client_id: str, client_secret: str) -> requests.Session:
- session = make_tracked_session(redact_values=(client_secret,))
+ session = make_tracked_session(retry=_GENESYS_CLOUD_RETRY, redact_values=(client_secret,))
session.auth = _make_auth(region, client_id, client_secret)
return session
diff --git a/products/warehouse_sources/sources/genesys_cloud/tests/test_genesys_cloud.py b/products/warehouse_sources/sources/genesys_cloud/tests/test_genesys_cloud.py
index 4cd90b8e99b0..04192dffd9cd 100644
--- a/products/warehouse_sources/sources/genesys_cloud/tests/test_genesys_cloud.py
+++ b/products/warehouse_sources/sources/genesys_cloud/tests/test_genesys_cloud.py
@@ -9,6 +9,7 @@ import requests
from products.warehouse_sources.sources.genesys_cloud import genesys_cloud
from products.warehouse_sources.sources.genesys_cloud._config import GenesysCloudSourceConfig
from products.warehouse_sources.sources.genesys_cloud.genesys_cloud import (
+ _GENESYS_CLOUD_RETRY,
GenesysCloudResumeConfig,
validate_credentials,
)
@@ -364,3 +365,20 @@ class TestValidateCredentials:
assert result == (False, "Select the Genesys Cloud region your organization is hosted in.")
assert network.requests_log == []
assert network.session_options == []
+
+
+class TestRetryPolicy:
+ @pytest.mark.parametrize(
+ "status_code,expected_retry",
+ [
+ (429, True),
+ (504, True),
+ (404, False),
+ ],
+ )
+ def test_analytics_post_retries_like_the_listing_gets(self, status_code, expected_retry):
+ # The analytics/user-analytics endpoints are read via POST; without the override below,
+ # DEFAULT_RETRY would only retry the listing/scan endpoints' GETs and let a transient
+ # 429/5xx on the POST query bubble up as an unhandled HTTPError.
+ for method in ("GET", "POST"):
+ assert _GENESYS_CLOUD_RETRY.is_retry(method, status_code) is expected_retry