Skip to content

Commit

Permalink
feat: bump otel dependencies + move reordering path to happen before …
Browse files Browse the repository at this point in the history
…any configurator import
  • Loading branch information
Tamir David authored and Tamir David committed Sep 2, 2024
1 parent a9521bb commit 23c515d
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 180 deletions.
9 changes: 5 additions & 4 deletions initializer/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# from .odigos_sampler import OdigosSampler
# from opentelemetry.sdk.trace.sampling import ParentBased

# Reorder the python sys.path to ensure that the user application's dependencies take precedence over the agent's dependencies.
# This is necessary because the user application's dependencies may be incompatible with those used by the agent.
reorder_python_path()

from opamp.http_client import OpAMPHTTPClient


Expand Down Expand Up @@ -49,10 +53,7 @@ def initialize_components(trace_exporters = None, metric_exporters = None, log_e
initialize_metrics_if_enabled(metric_exporters, resource)
initialize_logging_if_enabled(log_exporters, resource)

# Reorder the python sys.path to ensure that the user application's dependencies take precedence over the agent's dependencies.
# This is necessary because the user application's dependencies may be incompatible with those used by the agent.
reorder_python_path()
# Reload distro modules to ensure the new path is used.
# # Reload distro modules to ensure the new path is used.
reload_distro_modules()

except Exception as e:
Expand Down
13 changes: 10 additions & 3 deletions initializer/lib_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ def reload_distro_modules() -> None:
# Delete distro modules and their sub-modules, as they have been imported before the path was reordered.
# The distro modules will be re-imported from the new path.
needed_module_prefixes = [
'google.protobuf',
'requests',
'charset_normalizer',
'certifi',
'asgiref'
'asgiref',
'idna',
'deprecated',
'importlib_metadata',
Expand All @@ -28,7 +27,15 @@ def reload_distro_modules() -> None:
'typing_extensions',
]

excluded_modules = [
'urllib3_odigos',
'requests_odigos'
]

for module in list(sys.modules):
# Check if the module starts with any of the needed prefixes
# Check if the module starts with any of the needed prefixes, but not with any of the excluded prefixes.
if any(module.startswith(prefix) for prefix in excluded_modules):
continue

if any(module.startswith(prefix) for prefix in needed_module_prefixes):
del sys.modules[module]
14 changes: 7 additions & 7 deletions opamp/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import time
import threading
import requests
import requests_odigos
import logging

from uuid_extensions import uuid7
Expand Down Expand Up @@ -141,8 +141,8 @@ def worker(self):
server_to_agent = self.send_agent_to_server_message(agent_to_server)

self.update_remote_config_status(server_to_agent)

except requests.RequestException as e:
except requests_odigos.RequestException as e:
opamp_logger.error(f"Error fetching data: {e}")
self.condition.wait(30)

Expand All @@ -151,7 +151,7 @@ def send_heartbeat(self) -> opamp_pb2.ServerToAgent:
try:
agent_to_server = opamp_pb2.AgentToServer(remote_config_status=self.remote_config_status)
return self.send_agent_to_server_message(agent_to_server)
except requests.RequestException as e:
except requests_odigos.RequestException as e:
opamp_logger.error(f"Error sending heartbeat to OpAMP server: {e}")

def get_agent_description(self) -> opamp_pb2.AgentDescription:
Expand Down Expand Up @@ -208,12 +208,12 @@ def send_agent_to_server_message(self, message: opamp_pb2.AgentToServer) -> opam

try:
agent_message = attach(set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True))
response = requests.post(self.server_url, data=message_bytes, headers=headers, timeout=5)
response = requests_odigos.post(self.server_url, data=message_bytes, headers=headers, timeout=5)
response.raise_for_status()
except requests.Timeout:
except requests_odigos.Timeout:
opamp_logger.error("Timeout sending message to OpAMP server")
return opamp_pb2.ServerToAgent()
except requests.ConnectionError as e:
except requests_odigos.ConnectionError as e:
opamp_logger.error(f"Error sending message to OpAMP server: {e}")
return opamp_pb2.ServerToAgent()
finally:
Expand Down
Loading

0 comments on commit 23c515d

Please sign in to comment.