diff --git a/examples/flask_example/flaskapp.py b/examples/flask_example/flaskapp.py index 62eab29..8abb3c5 100644 --- a/examples/flask_example/flaskapp.py +++ b/examples/flask_example/flaskapp.py @@ -48,7 +48,7 @@ def track_revenue(user_id): @app.route("/flush") def flush_event(): amp_client.flush() - return "

All events flushed

" + return f"

All events flushed

" if __name__ == "__main__": diff --git a/src/amplitude/config.py b/src/amplitude/config.py index 838ab59..ac70308 100644 --- a/src/amplitude/config.py +++ b/src/amplitude/config.py @@ -33,7 +33,6 @@ class Config: storage_provider (amplitude.storage.StorageProvider, optional): Default to InMemoryStorageProvider. Provide storage instance for events buffer. plan (amplitude.event.Plan, optional): Tracking plan information. Default to None. - library_context (str, optional): Library context information. Default to None. Properties: options: A dictionary contains minimum id length information. None if min_id_length not set. @@ -56,8 +55,7 @@ def __init__(self, api_key: str = None, use_batch: bool = False, server_url: Optional[str] = None, storage_provider: StorageProvider = InMemoryStorageProvider(), - plan: Plan = None, - library_context: str = None): + plan: Plan = None): """The constructor of Config class""" self.api_key: str = api_key self._flush_queue_size: int = flush_queue_size @@ -73,7 +71,6 @@ def __init__(self, api_key: str = None, self.storage_provider: StorageProvider = storage_provider self.opt_out: bool = False self.plan: Plan = plan - self.library_context: str = library_context def get_storage(self) -> Storage: """Use configured StorageProvider to create a Storage instance then return. diff --git a/src/amplitude/event.py b/src/amplitude/event.py index a84b296..3d25bb3 100644 --- a/src/amplitude/event.py +++ b/src/amplitude/event.py @@ -112,7 +112,6 @@ def get_plan_body(self): "session_id": ["session_id", int], "insert_id": ["insert_id", str], "library": ["library", str], - "library_context": ["library_context", str], "plan": ["plan", Plan], "group_properties": ["group_properties", dict], "partner_id": ["partner_id", str], @@ -158,7 +157,6 @@ class EventOptions: session_id (int, optional): The start timestamp of the session in milliseconds. insert_id (str, optional): A unique identifier for the event. Events sent with the same insert_id and device_id we have already seen before within the past 7 days will be deduplicated. - library_context (str, optional): Library context information, e.g., used by SDK library loader/wrapper. plan (Plan, optional): Tracking plan properties. partner_id (str, optional): The partner id. version_name (str, optional): The version name. @@ -204,7 +202,6 @@ def __init__(self, user_id: Optional[str] = None, event_id: Optional[int] = None, session_id: Optional[int] = None, insert_id: Optional[str] = None, - library_context: Optional[str] = None, plan: Optional[Plan] = None, partner_id: Optional[str] = None, version_name: Optional[str] = None, @@ -242,7 +239,6 @@ def __init__(self, user_id: Optional[str] = None, self.session_id: Optional[int] = None self.insert_id: Optional[str] = None self.library: Optional[str] = None - self.library_context: Optional[str] = None self.plan: Optional[Plan] = None self.partner_id: Optional[str] = None self.version_name: Optional[str] = None @@ -277,7 +273,6 @@ def __init__(self, user_id: Optional[str] = None, self["event_id"] = event_id self["session_id"] = session_id self["insert_id"] = insert_id - self["library_context"] = library_context self["plan"] = plan self["partner_id"] = partner_id self["version_name"] = version_name @@ -398,7 +393,6 @@ class BaseEvent(EventOptions): session_id (int, optional): The start timestamp of the session in milliseconds. insert_id (str, optional): A unique identifier for the event. Events sent with the same insert_id and device_id we have already seen before within the past 7 days will be deduplicated. - library_context (str, optional): Library context information, e.g., used by SDK library loader/wrapper. plan (Plan, optional): Tracking plan properties. partner_id (str, optional): The partner id. callback (callable, optional): Event level callback method. Triggered when event is sent or failed. Take three @@ -444,7 +438,6 @@ def __init__(self, event_type: str, event_id: Optional[int] = None, session_id: Optional[int] = None, insert_id: Optional[str] = None, - library_context: Optional[str] = None, plan: Optional[Plan] = None, partner_id: Optional[str] = None, callback: Optional[Callable[[EventOptions, int, Optional[str]], None]] = None): @@ -480,7 +473,6 @@ def __init__(self, event_type: str, event_id=event_id, session_id=session_id, insert_id=insert_id, - library_context=library_context, plan=plan, partner_id=partner_id, callback=callback) @@ -737,7 +729,6 @@ class GroupIdentifyEvent(BaseEvent): session_id (int, optional): The start timestamp of the session in milliseconds. insert_id (str, optional): A unique identifier for the event. Events sent with the same insert_id and device_id we have already seen before within the past 7 days will be deduplicated. - library_context (str, optional): Library context information, e.g., used by SDK library loader/wrapper. plan (Plan, optional): Tracking plan properties. partner_id (str, optional): The partner id. callback (callable, optional): Event level callback method. Triggered when event is sent or failed. Take three @@ -780,7 +771,6 @@ def __init__(self, user_id: Optional[str] = None, event_id: Optional[int] = None, session_id: Optional[int] = None, insert_id: Optional[str] = None, - library_context: Optional[str] = None, plan: Optional[Plan] = None, partner_id: Optional[str] = None, callback: Optional[Callable[[EventOptions, int, Optional[str]], None]] = None, @@ -821,7 +811,6 @@ def __init__(self, user_id: Optional[str] = None, event_id=event_id, session_id=session_id, insert_id=insert_id, - library_context=library_context, plan=plan, partner_id=partner_id, callback=callback) @@ -872,7 +861,6 @@ class IdentifyEvent(BaseEvent): session_id (int, optional): The start timestamp of the session in milliseconds. insert_id (str, optional): A unique identifier for the event. Events sent with the same insert_id and device_id we have already seen before within the past 7 days will be deduplicated. - library_context (str, optional): Library context information, e.g., used by SDK library loader/wrapper. plan (Plan, optional): Tracking plan properties. partner_id (str, optional): The partner id. callback (callable, optional): Event level callback method. Triggered when event is sent or failed. Take three @@ -915,7 +903,6 @@ def __init__(self, user_id: Optional[str] = None, event_id: Optional[int] = None, session_id: Optional[int] = None, insert_id: Optional[str] = None, - library_context: Optional[str] = None, plan: Optional[Plan] = None, partner_id: Optional[str] = None, callback: Optional[Callable[[EventOptions, int, Optional[str]], None]] = None, @@ -955,7 +942,6 @@ def __init__(self, user_id: Optional[str] = None, event_id=event_id, session_id=session_id, insert_id=insert_id, - library_context=library_context, plan=plan, partner_id=partner_id, callback=callback) @@ -1095,7 +1081,6 @@ class RevenueEvent(BaseEvent): session_id (int, optional): The start timestamp of the session in milliseconds. insert_id (str, optional): A unique identifier for the event. Events sent with the same insert_id and device_id we have already seen before within the past 7 days will be deduplicated. - library_context (str, optional): Library context information, e.g., used by SDK library loader/wrapper. plan (Plan, optional): Tracking plan properties. partner_id (str, optional): The partner id. callback (callable, optional): Event level callback method. Triggered when event is sent or failed. Take three @@ -1138,7 +1123,6 @@ def __init__(self, user_id: Optional[str] = None, event_id: Optional[int] = None, session_id: Optional[int] = None, insert_id: Optional[str] = None, - library_context: Optional[str] = None, plan: Optional[Plan] = None, partner_id: Optional[str] = None, callback: Optional[Callable[[EventOptions, int, Optional[str]], None]] = None, @@ -1179,7 +1163,6 @@ def __init__(self, user_id: Optional[str] = None, event_id=event_id, session_id=session_id, insert_id=insert_id, - library_context=library_context, plan=plan, partner_id=partner_id, callback=callback) diff --git a/src/amplitude/plugin.py b/src/amplitude/plugin.py index e39bc42..469521a 100644 --- a/src/amplitude/plugin.py +++ b/src/amplitude/plugin.py @@ -178,17 +178,15 @@ class ContextPlugin(Plugin): Also set event default timestamp and insert_id if not set elsewhere. Methods: - apply_context_data(event): - - Add SDK name and version to event.library. + apply_context_data(event): Add SDK name and version to event.library. execute(event): Set event default timestamp and insert_id if not set elsewhere. - - Add SDK name and version to event.library. - - Add library context information to event.library_context. + Add SDK name and version to event.library. """ def __init__(self): """The constructor of ContextPlugin class""" super().__init__(constants.PluginType.BEFORE) - self.library = f"{constants.SDK_LIBRARY}/{constants.SDK_VERSION}" + self.context_string = f"{constants.SDK_LIBRARY}/{constants.SDK_VERSION}" self.configuration = None def setup(self, client): @@ -200,10 +198,10 @@ def apply_context_data(self, event: BaseEvent): Args: event (BaseEvent): The event to be processed. """ - event.library = self.library + event.library = self.context_string def execute(self, event: BaseEvent) -> BaseEvent: - """Set event default timestamp and insert_id if not set elsewhere. Apply context data to event. + """Set event default timestamp and insert_id if not set elsewhere. Add SDK name and version to event.library. Args: event (BaseEvent): The event to be processed. @@ -214,8 +212,6 @@ def execute(self, event: BaseEvent) -> BaseEvent: event["insert_id"] = str(uuid.uuid4()) if self.configuration.plan and (not event.plan): event["plan"] = self.configuration.plan - if self.configuration.library_context and (not event.library_context): - event["library_context"] = self.configuration.library_context self.apply_context_data(event) return event diff --git a/src/test/test_event.py b/src/test/test_event.py index 4021067..a54a835 100644 --- a/src/test/test_event.py +++ b/src/test/test_event.py @@ -51,20 +51,12 @@ def test_base_event_set_plan_attribute_success(self): "event_type": "test_event", "plan": {"branch": "test_branch", "versionId": "v1.1"}}, event.get_event_body()) - def test_base_event_set_library_context_attribute_success(self): - event = BaseEvent("test_event", user_id="test_user") - event["library_context"] = "test_library_context/1.x" - self.assertEqual({"user_id": "test_user", - "event_type": "test_event", - "library_context": "test_library_context/1.x"}, event.get_event_body()) - def test_base_event_load_event_options_update_attributes_value(self): event = BaseEvent(event_type="test_event", event_properties={"properties1": "test"}, time=0) - event_options = EventOptions(user_id="test_user", device_id="test_device", library_context="test_library_context/1.x", time=10) + event_options = EventOptions(user_id="test_user", device_id="test_device", time=10) event.load_event_options(event_options) expect_event_body = {"user_id": "test_user", "device_id": "test_device", - "library_context": "test_library_context/1.x", "time": 10, "event_type": "test_event", "event_properties": {"properties1": "test"}} diff --git a/src/test/test_plugin.py b/src/test/test_plugin.py index 7dabca2..ee342f7 100644 --- a/src/test/test_plugin.py +++ b/src/test/test_plugin.py @@ -24,22 +24,18 @@ def test_plugin_initialize_amplitude_client_context_plugin_creation_success(self client.shutdown() def test_plugin_context_plugin_execute_event_success(self): - test_library_context = "test_library_context" context_plugin = ContextPlugin() context_plugin.setup(Amplitude("test_api_key")) context_plugin.configuration.plan = Plan(source="test_source") - context_plugin.configuration.library_context = test_library_context event = BaseEvent("test_event", user_id="test_user") self.assertIsNone(event.time) self.assertIsNone(event.insert_id) self.assertIsNone(event.library) - self.assertIsNone(event.library_context) self.assertIsNone(event.plan) context_plugin.execute(event) self.assertTrue(isinstance(event.time, int)) self.assertTrue(isinstance(event.insert_id, str)) self.assertTrue(isinstance(event.library, str)) - self.assertEqual(event.library_context, test_library_context) self.assertTrue(isinstance(event.plan, Plan)) def test_plugin_event_plugin_process_event_success(self): @@ -65,14 +61,12 @@ def test_plugin_destination_plugin_add_remove_plugin_success(self): self.assertTrue(isinstance(event.time, int)) self.assertTrue(isinstance(event.insert_id, str)) self.assertTrue(isinstance(event.library, str)) - self.assertIsNone(event.library_context) destination_plugin.remove(context_plugin) event = BaseEvent("test_event", user_id="test_user") destination_plugin.execute(event) self.assertIsNone(event.time) self.assertIsNone(event.insert_id) self.assertIsNone(event.library) - self.assertIsNone(event.library_context) if __name__ == '__main__':