@@ -235,6 +235,41 @@ def test_configurator_ignores_opamp_without_endpoint(self, client_mock, agent_mo
235235 client_mock .assert_not_called ()
236236 agent_mock .assert_not_called ()
237237
238+ @mock .patch .dict ("os.environ" , {"OTEL_LOG_LEVEL" : "debug" }, clear = True )
239+ @mock .patch ("elasticotel.distro.config.logger" )
240+ def test_configurator_applies_elastic_otel_log_level (self , logger_mock ):
241+ ElasticOpenTelemetryConfigurator ()._configure ()
242+
243+ logger_mock .error .assert_not_called ()
244+
245+ self .assertEqual (logging .getLogger ("opentelemetry" ).getEffectiveLevel (), logging .DEBUG )
246+ self .assertEqual (logging .getLogger ("elasticotel" ).getEffectiveLevel (), logging .DEBUG )
247+
248+ @mock .patch .dict ("os.environ" , {}, clear = True )
249+ @mock .patch ("elasticotel.distro.config.logger" )
250+ def test_configurator_handles_elastic_otel_log_level_not_set (self , logger_mock ):
251+ ElasticOpenTelemetryConfigurator ()._configure ()
252+
253+ logger_mock .error .assert_not_called ()
254+
255+ self .assertEqual (logging .getLogger ("opentelemetry" ).getEffectiveLevel (), logging .WARNING )
256+ self .assertEqual (logging .getLogger ("elasticotel" ).getEffectiveLevel (), logging .WARNING )
257+
258+ @mock .patch .dict ("os.environ" , {"OTEL_LOG_LEVEL" : "invalid" }, clear = True )
259+ def test_configurator_handles_invalid_elastic_otel_log_level (self ):
260+ with self .assertLogs ("elasticotel" , level = "ERROR" ) as cm :
261+ ElasticOpenTelemetryConfigurator ()._configure ()
262+
263+ self .assertEqual (
264+ cm .output ,
265+ [
266+ "ERROR:elasticotel.distro.config:Logging level not handled: invalid" ,
267+ ],
268+ )
269+
270+ self .assertEqual (logging .getLogger ("opentelemetry" ).getEffectiveLevel (), logging .WARNING )
271+ self .assertEqual (logging .getLogger ("elasticotel" ).getEffectiveLevel (), logging .WARNING )
272+
238273
239274class TestOpAMPHandler (TestCase ):
240275 @mock .patch .object (logging , "getLogger" )
@@ -247,8 +282,9 @@ def test_does_nothing_without_remote_config(self, get_logger_mock):
247282 get_logger_mock .assert_not_called ()
248283
249284 @mock .patch ("elasticotel.distro.config._get_config" )
285+ @mock .patch .object (Config , "_handle_logging" )
250286 @mock .patch .object (logging , "getLogger" )
251- def test_ignores_non_elastic_filename (self , get_logger_mock , get_config_mock ):
287+ def test_ignores_non_elastic_filename (self , get_logger_mock , handle_logging_mock , get_config_mock ):
252288 get_config_mock .return_value = Config ()
253289 agent = mock .Mock ()
254290 client = mock .Mock ()
@@ -265,7 +301,7 @@ def test_ignores_non_elastic_filename(self, get_logger_mock, get_config_mock):
265301 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
266302 )
267303 client ._update_effective_config .assert_called_once_with (
268- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
304+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
269305 )
270306 client ._build_remote_config_status_response_message .assert_called_once_with (
271307 client ._update_remote_config_status ()
@@ -318,17 +354,17 @@ def test_sets_logging_to_default_info_without_logging_level_entry_in_config(self
318354 get_logger_mock .assert_has_calls (
319355 [
320356 mock .call ("opentelemetry" ),
321- mock .call ().setLevel (logging .INFO ),
357+ mock .call ().setLevel (logging .WARNING ),
322358 mock .call ("elasticotel" ),
323- mock .call ().setLevel (logging .INFO ),
359+ mock .call ().setLevel (logging .WARNING ),
324360 ]
325361 )
326362
327363 client ._update_remote_config_status .assert_called_once_with (
328364 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
329365 )
330366 client ._update_effective_config .assert_called_once_with (
331- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
367+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
332368 )
333369 client ._build_remote_config_status_response_message .assert_called_once_with (
334370 client ._update_remote_config_status ()
@@ -356,7 +392,7 @@ def test_warns_if_logging_level_does_not_match_our_map(self, get_logger_mock, ge
356392 client ._update_remote_config_status ()
357393 )
358394 client ._update_effective_config .assert_called_once_with (
359- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
395+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
360396 )
361397 agent .send .assert_called_once_with (payload = mock .ANY )
362398 client ._build_full_state_message .assert_not_called ()
@@ -382,7 +418,7 @@ def test_sets_matching_sampling_rate(self, get_tracer_provider_mock, get_config_
382418 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
383419 )
384420 client ._update_effective_config .assert_called_once_with (
385- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "0.5" }}
421+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "0.5" }}
386422 )
387423 client ._build_remote_config_status_response_message .assert_called_once_with (
388424 client ._update_remote_config_status ()
@@ -413,7 +449,7 @@ def test_sets_sampling_rate_to_default_info_without_sampling_rate_entry_in_confi
413449 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
414450 )
415451 client ._update_effective_config .assert_called_once_with (
416- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
452+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
417453 )
418454 client ._build_remote_config_status_response_message .assert_called_once_with (
419455 client ._update_remote_config_status ()
@@ -447,7 +483,7 @@ def test_warns_if_sampling_rate_value_is_invalid(self, get_tracer_provider_mock,
447483 error_message = "Invalid sampling_rate unexpected" ,
448484 )
449485 client ._update_effective_config .assert_called_once_with (
450- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
486+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
451487 )
452488 client ._build_remote_config_status_response_message .assert_called_once_with (
453489 client ._update_remote_config_status ()
@@ -479,7 +515,7 @@ def test_warns_if_sampler_is_not_what_we_expect(self, get_tracer_provider_mock,
479515 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
480516 )
481517 client ._update_effective_config .assert_called_once_with (
482- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
518+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
483519 )
484520 client ._build_remote_config_status_response_message .assert_called_once_with (
485521 client ._update_remote_config_status ()
@@ -508,7 +544,7 @@ def test_ignores_tracer_provider_without_a_sampler(self, get_tracer_provider_moc
508544 remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
509545 )
510546 client ._update_effective_config .assert_called_once_with (
511- {"elastic" : {"logging_level" : "info " , "sampling_rate" : "1.0" }}
547+ {"elastic" : {"logging_level" : "warn " , "sampling_rate" : "1.0" }}
512548 )
513549 client ._build_remote_config_status_response_message .assert_called_once_with (
514550 client ._update_remote_config_status ()
0 commit comments