[CODE QUALITY]

pull/299/head
Kye 1 year ago
parent 5b4d7c485c
commit 37dbaf116b

@ -1,6 +1,11 @@
from swarms.telemetry.log_all import log_all_calls, log_calls from swarms.telemetry.log_all import log_all_calls, log_calls
from swarms.telemetry.posthog_utils import log_activity_posthog 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__ = [ __all__ = [
@ -10,5 +15,5 @@ __all__ = [
"generate_user_id", "generate_user_id",
"get_machine_id", "get_machine_id",
"get_system_info", "get_system_info",
"generate_unique_identifier" "generate_unique_identifier",
] ]

@ -4,6 +4,7 @@ import os
from dotenv import load_dotenv from dotenv import load_dotenv
from posthog import Posthog from posthog import Posthog
from swarms.telemetry.user_utils import generate_unique_identifier from swarms.telemetry.user_utils import generate_unique_identifier
# Load environment variables # Load environment variables
load_dotenv() load_dotenv()
@ -65,10 +66,13 @@ def log_activity_posthog(event_name: str, **event_properties):
return decorator_log_activity 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(): def my_function():
# Function logic here # Function logic here
return "Function executed successfully!" return "Function executed successfully!"
out = my_function() out = my_function()
print(out) print(out)

@ -3,6 +3,7 @@ import platform
import uuid import uuid
import socket import socket
# Helper functions # Helper functions
def generate_user_id(): def generate_user_id():
"""Generate user id """Generate user id
@ -12,6 +13,7 @@ def generate_user_id():
""" """
return str(uuid.uuid4()) return str(uuid.uuid4())
def get_machine_id(): def get_machine_id():
"""Get machine id """Get machine id
@ -19,9 +21,7 @@ def get_machine_id():
_type_: _description_ _type_: _description_
""" """
raw_id = platform.node() raw_id = platform.node()
hashed_id = hashlib.sha256( hashed_id = hashlib.sha256(raw_id.encode()).hexdigest()
raw_id.encode()
).hexdigest()
return hashed_id return hashed_id
@ -39,12 +39,18 @@ def get_system_info():
"architecture": platform.machine(), "architecture": platform.machine(),
"hostname": socket.gethostname(), "hostname": socket.gethostname(),
"ip_address": socket.gethostbyname(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(), "processor": platform.processor(),
"python_version": platform.python_version() "python_version": platform.python_version(),
} }
return info return info
def generate_unique_identifier(): def generate_unique_identifier():
"""Generate unique identifier """Generate unique identifier
@ -53,8 +59,5 @@ def generate_unique_identifier():
""" """
system_info = get_system_info() system_info = get_system_info()
unique_id = uuid.uuid5( unique_id = uuid.uuid5(uuid.NAMESPACE_DNS, str(system_info))
uuid.NAMESPACE_DNS,
str(system_info)
)
return str(unique_id) return str(unique_id)
Loading…
Cancel
Save