18
18
19
19
from azure .core .tracing .ext .opentelemetry_span import OpenTelemetrySpan
20
20
from azure .monitor .opentelemetry ._configure import (
21
+ _send_attach_warning ,
21
22
_setup_instrumentations ,
22
23
_setup_logging ,
23
24
_setup_metrics ,
24
25
_setup_tracing ,
25
26
configure_azure_monitor ,
26
27
)
28
+ from azure .monitor .opentelemetry ._diagnostics .diagnostic_logging import _DISTRO_DETECTS_ATTACH
27
29
28
30
29
31
TEST_RESOURCE = Resource ({"foo" : "bar" })
30
32
31
33
32
34
class TestConfigure (unittest .TestCase ):
35
+ @patch (
36
+ "azure.monitor.opentelemetry._configure._send_attach_warning" ,
37
+ )
33
38
@patch (
34
39
"azure.monitor.opentelemetry._configure._setup_instrumentations" ,
35
40
)
@@ -48,6 +53,7 @@ def test_configure_azure_monitor(
48
53
logging_mock ,
49
54
metrics_mock ,
50
55
instrumentation_mock ,
56
+ detect_attach_mock ,
51
57
):
52
58
kwargs = {
53
59
"connection_string" : "test_cs" ,
@@ -57,6 +63,7 @@ def test_configure_azure_monitor(
57
63
logging_mock .assert_called_once ()
58
64
metrics_mock .assert_called_once ()
59
65
instrumentation_mock .assert_called_once ()
66
+ detect_attach_mock .assert_called_once ()
60
67
61
68
@patch (
62
69
"azure.monitor.opentelemetry._configure._setup_instrumentations" ,
@@ -464,3 +471,28 @@ def test_setup_instrumentations_disabled(
464
471
ep2_mock .load .assert_called_once ()
465
472
instrumentor_mock .instrument .assert_called_once ()
466
473
logger_mock .debug .assert_called_once ()
474
+
475
+ @patch ("azure.monitor.opentelemetry._configure.AzureDiagnosticLogging" )
476
+ @patch ("azure.monitor.opentelemetry._configure._is_attach_enabled" )
477
+ def test_send_attach_warning_true (
478
+ self ,
479
+ is_attach_enabled_mock ,
480
+ mock_diagnostics ,
481
+ ):
482
+ is_attach_enabled_mock .return_value = True
483
+ _send_attach_warning ()
484
+ mock_diagnostics .warning .assert_called_once_with (
485
+ "Distro detected that automatic attach may have occurred. Check your data to ensure that telemetry is not being duplicated. This may impact your cost." ,
486
+ _DISTRO_DETECTS_ATTACH ,
487
+ )
488
+
489
+ @patch ("azure.monitor.opentelemetry._configure.AzureDiagnosticLogging" )
490
+ @patch ("azure.monitor.opentelemetry._configure._is_attach_enabled" )
491
+ def test_send_attach_warning_false (
492
+ self ,
493
+ is_attach_enabled_mock ,
494
+ mock_diagnostics ,
495
+ ):
496
+ is_attach_enabled_mock .return_value = False
497
+ _send_attach_warning ()
498
+ mock_diagnostics .warning .assert_not_called ()
0 commit comments