Skip to content

Commit

Permalink
Merge pull request #12 from odigos-io/support-enterprise
Browse files Browse the repository at this point in the history
feat: support enterprise usecase
  • Loading branch information
tamirdavid1 authored Sep 2, 2024
2 parents 8b96c8e + 23c515d commit e882524
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 185 deletions.
20 changes: 11 additions & 9 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 All @@ -63,15 +64,14 @@ def initialize_components(trace_exporters = None, metric_exporters = None, log_e
def initialize_traces_if_enabled(trace_exporters, resource, span_processor = None):
traces_enabled = os.getenv(sdk_config.OTEL_TRACES_EXPORTER, "none").strip().lower()
if traces_enabled != "none":

provider = TracerProvider(resource=resource)


# TODO: uncomment once the OdigosSampler is implemented
# odigos_sampler = OdigosSampler()
# sampler = ParentBased(odigos_sampler)

# Exporting using exporters
if trace_exporters is not None:
provider = TracerProvider(resource=resource)
id_generator_name = sdk_config._get_id_generator()
id_generator = sdk_config._import_id_generator(id_generator_name)
provider.id_generator = id_generator
Expand All @@ -86,19 +86,21 @@ def initialize_traces_if_enabled(trace_exporters, resource, span_processor = Non

# Exporting using EBPF
else:
provider = TracerProvider()
set_tracer_provider(provider)
if span_processor is not None:
provider.add_span_processor(span_processor)

# return sampler

def initialize_metrics_if_enabled(metric_exporters, resource):
metrics_enabled = os.getenv(sdk_config.OTEL_METRICS_EXPORTER, "none").strip().lower()
if metrics_enabled != "none":
if metrics_enabled != "none" and metric_exporters:
sdk_config._init_metrics(metric_exporters, resource)

def initialize_logging_if_enabled(log_exporters, resource):
logging_enabled = os.getenv(sdk_config.OTEL_LOGS_EXPORTER, "none").strip().lower()
if logging_enabled != "none":
if logging_enabled != "none" and log_exporters:
sdk_config._init_logging(log_exporters, resource)


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 e882524

Please sign in to comment.