Skip to content

Commit e1c3b6b

Browse files
authored
fix(tracking): default ingestor host to us-east-1.gb-ingest.com (#167)
* fix(tracking): default ingestor host to us-east-1.gb-ingest.com Match growthbook/growthbook#6608, which replaced the legacy us1.gb-ingest.com alias with us-east-1.gb-ingest.com as the default ingest host. An explicitly set ingestor host still overrides it. * test(tracking): wait for the ingest POST with an Event instead of sleeping The tracking plugin posts from a daemon thread, so a fixed 50 ms sleep can fail on a slow CI worker, and a late POST could escape the requests.post patch. Wait on a threading.Event set by the fake post.
1 parent 9ab2b3d commit e1c3b6b

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ gb = GrowthBook(
541541
plugins=[
542542
request_context_plugin(), # Extracts request data
543543
growthbook_tracking_plugin(
544-
ingestor_host="https://gb-ingest.growthbook.io",
544+
ingestor_host="https://us-east-1.gb-ingest.com",
545545
# Optional: Add custom tracking callback
546546
additional_callback=my_custom_tracker
547547
)

‎growthbook/plugins/growthbook_tracking.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class GrowthBookTrackingPlugin(GrowthBookPlugin):
9494

9595
def __init__(
9696
self,
97-
ingestor_host: str = "https://us1.gb-ingest.com",
97+
ingestor_host: str = "https://us-east-1.gb-ingest.com",
9898
track_experiment_viewed: bool = True,
9999
track_feature_evaluated: bool = True,
100100
batch_size: int = 10,
@@ -106,7 +106,7 @@ def __init__(
106106
Initialize GrowthBook tracking plugin.
107107
108108
Args:
109-
ingestor_host: Base URL of the GrowthBook ingestor (default: ``https://us1.gb-ingest.com``).
109+
ingestor_host: Base URL of the GrowthBook ingestor (default: ``https://us-east-1.gb-ingest.com``).
110110
track_experiment_viewed: Whether to auto-track experiment viewed events.
111111
track_feature_evaluated: Whether to auto-track feature evaluated events.
112112
batch_size: Number of events to accumulate before flushing to the ingestor.

‎tests/test_plugins.py‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import asyncio
1010
import json
1111
import pytest
12+
import threading
1213
import unittest
1314
from unittest.mock import patch, MagicMock
1415
from growthbook import (
@@ -465,9 +466,11 @@ def my_logger(event_name, properties, user_context):
465466
def test_log_event_with_plugin_sends_correct_payload(self):
466467
"""Plugin wires the event logger; log_event triggers an ingestor POST."""
467468
posted = []
469+
sent = threading.Event()
468470

469471
def fake_post(url, data, headers, timeout):
470472
posted.append({"url": url, "body": json.loads(data), "headers": headers})
473+
sent.set()
471474
response = MagicMock()
472475
response.status_code = 200
473476
return response
@@ -478,14 +481,14 @@ def fake_post(url, data, headers, timeout):
478481
client_key="sdk-test-key",
479482
plugins=[
480483
growthbook_tracking_plugin(
481-
ingestor_host="https://us1.gb-ingest.com",
484+
ingestor_host="https://us-east-1.gb-ingest.com",
482485
batch_size=1, # flush immediately
483486
)
484487
],
485488
)
486489
gb.log_event("checkout_started", {"cart_value": 99})
487-
# Give the daemon thread a moment to post
488-
import time; time.sleep(0.05)
490+
# The POST runs on a daemon thread; wait for it while requests.post is still patched
491+
self.assertTrue(sent.wait(timeout=2), "tracking did not send events")
489492

490493
self.assertEqual(len(posted), 1, "Expected exactly one POST")
491494
url = posted[0]["url"]
@@ -509,6 +512,31 @@ def fake_post(url, data, headers, timeout):
509512
self.assertEqual(posted[0]["headers"]["Content-Type"], "text/plain")
510513
gb.destroy()
511514

515+
def test_default_ingestor_host_is_us_east_1(self):
516+
"""Without ingestor_host, events go to the us-east-1 ingest host."""
517+
posted = []
518+
sent = threading.Event()
519+
520+
def fake_post(url, data, headers, timeout):
521+
posted.append(url)
522+
sent.set()
523+
response = MagicMock()
524+
response.status_code = 200
525+
return response
526+
527+
with patch("requests.post", side_effect=fake_post):
528+
gb = GrowthBook(
529+
attributes={"id": "user-42"},
530+
client_key="sdk-test-key",
531+
plugins=[growthbook_tracking_plugin(batch_size=1)],
532+
)
533+
gb.log_event("checkout_started", {})
534+
# The POST runs on a daemon thread; wait for it while requests.post is still patched
535+
self.assertTrue(sent.wait(timeout=2), "tracking did not send events")
536+
537+
self.assertEqual(posted, ["https://us-east-1.gb-ingest.com/track?client_key=sdk-test-key"])
538+
gb.destroy()
539+
512540
def test_log_event_empty_properties(self):
513541
"""log_event works with no properties argument."""
514542
received = []
@@ -605,7 +633,7 @@ def test_async_client_plugin_wires_event_logger(self):
605633
Options(
606634
client_key="sdk-key",
607635
tracking_plugins=[
608-
growthbook_tracking_plugin(ingestor_host="https://us1.gb-ingest.com")
636+
growthbook_tracking_plugin(ingestor_host="https://us-east-1.gb-ingest.com")
609637
],
610638
)
611639
)

0 commit comments

Comments
 (0)