diff --git a/initializer/components.py b/initializer/components.py index a7cb715..a2943ff 100644 --- a/initializer/components.py +++ b/initializer/components.py @@ -20,7 +20,7 @@ # 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 +from opamp.http_client import OpAMPHTTPClient, MockOpAMPClient MINIMUM_PYTHON_SUPPORTED_VERSION = (3, 8) @@ -107,6 +107,10 @@ def initialize_logging_if_enabled(log_exporters, resource): def start_opamp_client(event): + + if os.getenv('DISABLE_OPAMP_CLIENT', 'false').strip().lower() == 'true': + return MockOpAMPClient(event) + condition = threading.Condition(threading.Lock()) client = OpAMPHTTPClient(event, condition) diff --git a/opamp/http_client.py b/opamp/http_client.py index a6b79b8..7bb1e83 100644 --- a/opamp/http_client.py +++ b/opamp/http_client.py @@ -276,4 +276,16 @@ def update_remote_config_status(self, server_to_agent: opamp_pb2.ServerToAgent) self.remote_config_status = remote_config_status return True - return False \ No newline at end of file + return False + + +# Mock client class for non-OpAMP installations +# This class simulates the OpAMP client when the OpAMP server is not available. +# To activate it, set the environment variable DISABLE_OPAMP_CLIENT to true. +class MockOpAMPClient: + def __init__(self, event, *args, **kwargs): + self.resource_attributes = {'odigos.opamp': 'disabled'} + event.set() + + def shutdown(self, custom_failure_message=None): + pass \ No newline at end of file