From c229b70f73e200b8e492382ca401931927cdbb6f Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Thu, 2 May 2024 14:46:09 -0700 Subject: [PATCH] allow host env opt out (#174) * allow host env opt out * still get sdk and os * use env var * use env var --- agentops/client.py | 6 ++++-- agentops/host_env.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/agentops/client.py b/agentops/client.py index cca33753..57a80df8 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -4,7 +4,7 @@ Classes: Client: Provides methods to interact with the AgentOps service. """ - +import os from .event import ActionEvent, ErrorEvent, Event from .enums import EndState from .helpers import get_ISO_time, singleton, check_call_stack_for_agent_id @@ -76,6 +76,8 @@ def __init__(self, self._session = None self._worker = None + self._env_data_opt_out = os.getenv('AGENTOPS_ENV_DATA_OPT_OUT') and os.getenv('AGENTOPS_ENV_DATA_OPT_OUT').lower() == 'true' + try: self.config = Configuration(api_key=api_key, parent_key=parent_key, @@ -236,7 +238,7 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi if not config and not self.config: return logger.warning("🖇 AgentOps: Cannot start session - missing configuration") - self._session = Session(inherited_session_id or uuid4(), tags or self._tags_for_future_session, host_env=get_host_env()) + self._session = Session(inherited_session_id or uuid4(), tags or self._tags_for_future_session, host_env=get_host_env(self._env_data_opt_out)) self._worker = Worker(config or self.config) start_session_result = self._worker.start_session(self._session) if not start_session_result: diff --git a/agentops/host_env.py b/agentops/host_env.py index 42974a43..3b289033 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -54,11 +54,17 @@ def get_disk_details(): return disk_info -def get_host_env(): - return { - "SDK": get_sdk_details(), - "OS": get_os_details(), - "CPU": get_cpu_details(), - "RAM": get_ram_details(), - "Disk": get_disk_details(), - } +def get_host_env(opt_out: bool = False): + if opt_out: + return { + "SDK": get_sdk_details(), + "OS": get_os_details() + } + else: + return { + "SDK": get_sdk_details(), + "OS": get_os_details(), + "CPU": get_cpu_details(), + "RAM": get_ram_details(), + "Disk": get_disk_details(), + }