Skip to content

Commit 5dd2265

Browse files
committed
feat!: rename EventProcessorConfig.analytics_server_url to events_api_url and default it
Default points to https://events.api.flagsmith.com/ so callers don't have to specify it for cloud Flagsmith. Self-hosted users override via the events_api_url field. BREAKING CHANGE: EventProcessorConfig field analytics_server_url renamed to events_api_url.
1 parent 629ae12 commit 5dd2265

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

flagsmith/analytics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
FLAG_EXPOSURE_EVENT: typing.Final[str] = "$flag_exposure"
2121

22+
DEFAULT_EVENT_API_URL: typing.Final[str] = "https://events.api.flagsmith.com/"
23+
2224
session = FuturesSession(max_workers=4)
2325

2426

@@ -74,7 +76,7 @@ def track_feature(self, feature_name: str) -> None:
7476

7577
@dataclass
7678
class EventProcessorConfig:
77-
analytics_server_url: str
79+
events_api_url: str = DEFAULT_EVENT_API_URL
7880
max_buffer_items: int = 1000
7981
flush_interval_seconds: float = 10.0
8082

@@ -91,7 +93,7 @@ def __init__(
9193
config: EventProcessorConfig,
9294
environment_key: str,
9395
) -> None:
94-
url = config.analytics_server_url
96+
url = config.events_api_url
9597
if not url.endswith("/"):
9698
url = f"{url}/"
9799
self._batch_endpoint = f"{url}v1/events"

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def analytics_processor() -> AnalyticsProcessor:
3232

3333
@pytest.fixture()
3434
def event_processor_config() -> EventProcessorConfig:
35-
return EventProcessorConfig(analytics_server_url="http://test_analytics/")
35+
return EventProcessorConfig(events_api_url="http://test_analytics/")
3636

3737

3838
@pytest.fixture()

tests/test_event_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_track_exposure_event_uses_explicit_timestamp(
8686

8787
def test_auto_flush_on_buffer_full() -> None:
8888
config = EventProcessorConfig(
89-
analytics_server_url="http://test/", max_buffer_items=5
89+
events_api_url="http://test/", max_buffer_items=5
9090
)
9191
processor = EventProcessor(config=config, environment_key="key")
9292

@@ -139,7 +139,7 @@ def test_failed_flush_requeues_events(event_processor: EventProcessor) -> None:
139139

140140
def test_start_stop_lifecycle() -> None:
141141
config = EventProcessorConfig(
142-
analytics_server_url="http://test/", flush_interval_seconds=100
142+
events_api_url="http://test/", flush_interval_seconds=100
143143
)
144144
processor = EventProcessor(config=config, environment_key="key")
145145

tests/test_flagsmith.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def test_track_event_raises_without_config(api_key: str) -> None:
960960
def test_track_event_delegates_to_event_processor(
961961
mocker: MockerFixture, api_key: str
962962
) -> None:
963-
config = EventProcessorConfig(analytics_server_url="http://test/")
963+
config = EventProcessorConfig(events_api_url="http://test/")
964964
flagsmith = Flagsmith(environment_key=api_key, event_processor_config=config)
965965

966966
mock_track = mocker.patch.object(flagsmith._event_processor, "track_event")
@@ -992,7 +992,7 @@ def test_track_exposure_event_raises_without_config(api_key: str) -> None:
992992
def test_track_exposure_event_delegates_to_event_processor(
993993
mocker: MockerFixture, api_key: str
994994
) -> None:
995-
config = EventProcessorConfig(analytics_server_url="http://test/")
995+
config = EventProcessorConfig(events_api_url="http://test/")
996996
flagsmith = Flagsmith(environment_key=api_key, event_processor_config=config)
997997

998998
mock_track = mocker.patch.object(flagsmith._event_processor, "track_exposure_event")
@@ -1019,7 +1019,7 @@ def test_track_exposure_event_delegates_to_event_processor(
10191019
def test_get_experiment_flag_returns_flag_and_tracks_exposure(
10201020
mocker: MockerFixture, api_key: str, identities_json: str
10211021
) -> None:
1022-
config = EventProcessorConfig(analytics_server_url="http://test/")
1022+
config = EventProcessorConfig(events_api_url="http://test/")
10231023
flagsmith = Flagsmith(environment_key=api_key, event_processor_config=config)
10241024

10251025
mock_track = mocker.patch.object(flagsmith._event_processor, "track_exposure_event")
@@ -1049,7 +1049,7 @@ def test_get_experiment_flag_returns_flag_and_tracks_exposure(
10491049
def test_get_experiment_flag_skips_exposure_for_default_flag(
10501050
mocker: MockerFixture, api_key: str
10511051
) -> None:
1052-
config = EventProcessorConfig(analytics_server_url="http://test/")
1052+
config = EventProcessorConfig(events_api_url="http://test/")
10531053

10541054
def default_flag_handler(feature_name: str) -> DefaultFlag:
10551055
return DefaultFlag(enabled=True, value="default-variant")

0 commit comments

Comments
 (0)