@@ -135,6 +135,7 @@ def test_configurator_sets_up_opamp_with_http_endpoint(self, client_mock, agent_
135135 client_mock .assert_called_once_with (
136136 endpoint = "http://localhost:4320/v1/opamp" ,
137137 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
138+ headers = None ,
138139 )
139140 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
140141 agent_mock .start .assert_called_once_with ()
@@ -158,6 +159,32 @@ def test_configurator_sets_up_opamp_with_https_endpoint(self, client_mock, agent
158159 client_mock .assert_called_once_with (
159160 endpoint = "https://localhost:4320/v1/opamp" ,
160161 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
162+ headers = None ,
163+ )
164+ agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
165+ agent_mock .start .assert_called_once_with ()
166+
167+ @mock .patch .dict (
168+ "os.environ" ,
169+ {
170+ "ELASTIC_OTEL_OPAMP_ENDPOINT" : "http://localhost:4320/v1/opamp" ,
171+ "ELASTIC_OTEL_OPAMP_HEADERS" : "Authorization=ApiKey foobar===" ,
172+ "OTEL_RESOURCE_ATTRIBUTES" : "service.name=service,deployment.environment.name=dev" ,
173+ },
174+ clear = True ,
175+ )
176+ @mock .patch ("elasticotel.distro.OpAMPAgent" )
177+ @mock .patch ("elasticotel.distro.OpAMPClient" )
178+ def test_configurator_sets_up_opamp_with_headers_from_environment_variable (self , client_mock , agent_mock ):
179+ client_mock .return_value = client_mock
180+ agent_mock .return_value = agent_mock
181+
182+ ElasticOpenTelemetryConfigurator ()._configure ()
183+
184+ client_mock .assert_called_once_with (
185+ endpoint = "http://localhost:4320/v1/opamp" ,
186+ agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
187+ headers = {"authorization" : "ApiKey foobar===" },
161188 )
162189 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
163190 agent_mock .start .assert_called_once_with ()
@@ -181,6 +208,7 @@ def test_configurator_adds_path_to_opamp_endpoint_if_missing(self, client_mock,
181208 client_mock .assert_called_once_with (
182209 endpoint = "https://localhost:4320/v1/opamp" ,
183210 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
211+ headers = None ,
184212 )
185213 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
186214 agent_mock .start .assert_called_once_with ()
@@ -204,6 +232,7 @@ def test_configurator_sets_up_opamp_without_deployment_environment_name(self, cl
204232 client_mock .assert_called_once_with (
205233 endpoint = "https://localhost:4320/v1/opamp" ,
206234 agent_identifying_attributes = {"service.name" : "service" },
235+ headers = None ,
207236 )
208237 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
209238 agent_mock .start .assert_called_once_with ()
0 commit comments