diff --git a/swarms/telemetry/__init__.py b/swarms/telemetry/__init__.py index 2e33a86a..fdac5bf5 100644 --- a/swarms/telemetry/__init__.py +++ b/swarms/telemetry/__init__.py @@ -1,6 +1,11 @@ from swarms.telemetry.log_all import log_all_calls, log_calls from swarms.telemetry.posthog_utils import log_activity_posthog -from swarms.telemetry.user_utils import generate_user_id, get_machine_id, get_system_info, generate_unique_identifier +from swarms.telemetry.user_utils import ( + generate_user_id, + get_machine_id, + get_system_info, + generate_unique_identifier, +) __all__ = [ @@ -10,5 +15,5 @@ __all__ = [ "generate_user_id", "get_machine_id", "get_system_info", - "generate_unique_identifier" -] \ No newline at end of file + "generate_unique_identifier", +] diff --git a/swarms/telemetry/posthog_utils.py b/swarms/telemetry/posthog_utils.py index d8bb51ec..f9796f4e 100644 --- a/swarms/telemetry/posthog_utils.py +++ b/swarms/telemetry/posthog_utils.py @@ -4,6 +4,7 @@ import os from dotenv import load_dotenv from posthog import Posthog from swarms.telemetry.user_utils import generate_unique_identifier + # Load environment variables load_dotenv() @@ -65,10 +66,13 @@ def log_activity_posthog(event_name: str, **event_properties): return decorator_log_activity -@log_activity_posthog('function_executed', function_name='my_function') +@log_activity_posthog( + "function_executed", function_name="my_function" +) def my_function(): # Function logic here return "Function executed successfully!" + out = my_function() -print(out) \ No newline at end of file +print(out) diff --git a/swarms/telemetry/user_utils.py b/swarms/telemetry/user_utils.py index 613d85cc..74667326 100644 --- a/swarms/telemetry/user_utils.py +++ b/swarms/telemetry/user_utils.py @@ -1,7 +1,8 @@ import hashlib import platform -import uuid -import socket +import uuid +import socket + # Helper functions def generate_user_id(): @@ -12,6 +13,7 @@ def generate_user_id(): """ return str(uuid.uuid4()) + def get_machine_id(): """Get machine id @@ -19,9 +21,7 @@ def get_machine_id(): _type_: _description_ """ raw_id = platform.node() - hashed_id = hashlib.sha256( - raw_id.encode() - ).hexdigest() + hashed_id = hashlib.sha256(raw_id.encode()).hexdigest() return hashed_id @@ -39,12 +39,18 @@ def get_system_info(): "architecture": platform.machine(), "hostname": socket.gethostname(), "ip_address": socket.gethostbyname(socket.gethostname()), - "mac_address": ':'.join(['{:02x}'.format((uuid.getnode() >> elements) & 0xff) for elements in range(0, 2 * 6, 8)][::-1]), + "mac_address": ":".join( + [ + "{:02x}".format((uuid.getnode() >> elements) & 0xFF) + for elements in range(0, 2 * 6, 8) + ][::-1] + ), "processor": platform.processor(), - "python_version": platform.python_version() + "python_version": platform.python_version(), } return info + def generate_unique_identifier(): """Generate unique identifier @@ -53,8 +59,5 @@ def generate_unique_identifier(): """ system_info = get_system_info() - unique_id = uuid.uuid5( - uuid.NAMESPACE_DNS, - str(system_info) - ) - return str(unique_id) \ No newline at end of file + unique_id = uuid.uuid5(uuid.NAMESPACE_DNS, str(system_info)) + return str(unique_id)