1515from ddtrace ._trace ._span_pointer import _SpanPointerDirection
1616from ddtrace ._trace ._span_pointer import _SpanPointerDescription
1717
18+ from datadog_lambda .config import config
1819from datadog_lambda .constants import (
1920 SamplingPriority ,
2021 TraceHeader ,
@@ -251,20 +252,16 @@ def test_extract_dd_trace_context(event, expect):
251252
252253class TestExtractAndGetDDTraceContext (unittest .TestCase ):
253254 def setUp (self ):
254- global dd_tracing_enabled
255- dd_tracing_enabled = False
256255 os .environ ["_X_AMZN_TRACE_ID" ] = fake_xray_header_value
257256 patcher = patch ("datadog_lambda.tracing.send_segment" )
258257 self .mock_send_segment = patcher .start ()
259258 self .addCleanup (patcher .stop )
260- patcher = patch ("datadog_lambda.tracing .is_lambda_context" )
259+ patcher = patch ("datadog_lambda.config.Config .is_lambda_context" )
261260 self .mock_is_lambda_context = patcher .start ()
262261 self .mock_is_lambda_context .return_value = True
263262 self .addCleanup (patcher .stop )
264263
265264 def tearDown (self ):
266- global dd_tracing_enabled
267- dd_tracing_enabled = False
268265 del os .environ ["_X_AMZN_TRACE_ID" ]
269266
270267 @with_trace_propagation_style ("datadog" )
@@ -975,6 +972,7 @@ def test_convert_xray_sampling(self):
975972
976973class TestLogsInjection (unittest .TestCase ):
977974 def setUp (self ):
975+ config .reset ()
978976 patcher = patch ("datadog_lambda.tracing.get_dd_trace_context_obj" )
979977 self .mock_get_dd_trace_context = patcher .start ()
980978 self .mock_get_dd_trace_context .return_value = Context (
@@ -984,11 +982,12 @@ def setUp(self):
984982 )
985983 self .addCleanup (patcher .stop )
986984
987- patcher = patch ("datadog_lambda.tracing .is_lambda_context" )
985+ patcher = patch ("datadog_lambda.config.Config .is_lambda_context" )
988986 self .mock_is_lambda_context = patcher .start ()
989987 self .mock_is_lambda_context .return_value = True
990988 self .addCleanup (patcher .stop )
991989
990+ @patch ("datadog_lambda.config.Config.trace_enabled" , False )
992991 def test_set_correlation_ids (self ):
993992 set_correlation_ids ()
994993 span = tracer .current_span ()
@@ -1124,13 +1123,11 @@ def test_function_with_span_pointers(self):
11241123
11251124class TestSetTraceRootSpan (unittest .TestCase ):
11261125 def setUp (self ):
1127- global dd_tracing_enabled
1128- dd_tracing_enabled = False
11291126 os .environ ["_X_AMZN_TRACE_ID" ] = fake_xray_header_value
11301127 patcher = patch ("datadog_lambda.tracing.send_segment" )
11311128 self .mock_send_segment = patcher .start ()
11321129 self .addCleanup (patcher .stop )
1133- patcher = patch ("datadog_lambda.tracing .is_lambda_context" )
1130+ patcher = patch ("datadog_lambda.config.Config .is_lambda_context" )
11341131 self .mock_is_lambda_context = patcher .start ()
11351132 self .mock_is_lambda_context .return_value = True
11361133 self .addCleanup (patcher .stop )
@@ -1143,8 +1140,6 @@ def setUp(self):
11431140 self .addCleanup (patcher .stop )
11441141
11451142 def tearDown (self ):
1146- global dd_tracing_enabled
1147- dd_tracing_enabled = False
11481143 del os .environ ["_X_AMZN_TRACE_ID" ]
11491144
11501145 def test_mixed_parent_context_when_merging (self ):
@@ -1245,6 +1240,7 @@ def test_get_service_mapping(self):
12451240 create_service_mapping (os .environ ["DD_SERVICE_MAPPING" ])
12461241 )
12471242 self .assertEqual (self .get_service_mapping (), expected_output )
1243+ del os .environ ["DD_SERVICE_MAPPING" ]
12481244
12491245 def test_set_service_mapping (self ):
12501246 new_service_mapping = {"api3" : "service3" , "api4" : "service4" }
@@ -1285,6 +1281,8 @@ def test_determine_service_name(self):
12851281 "default" ,
12861282 )
12871283
1284+ del os .environ ["DD_SERVICE_MAPPING" ]
1285+
12881286 def test_remaps_all_inferred_span_service_names_from_api_gateway_event (self ):
12891287 new_service_mapping = {"lambda_api_gateway" : "new-name" }
12901288 self .set_service_mapping (new_service_mapping )
@@ -2386,7 +2384,7 @@ def test_deterministic_m5_hash__always_leading_with_zero(self):
23862384
23872385
23882386class TestExceptionOutsideHandler (unittest .TestCase ):
2389- @patch ("datadog_lambda.tracing.dd_tracing_enabled " , True )
2387+ @patch ("datadog_lambda.config.Config.trace_enabled " , True )
23902388 @patch ("datadog_lambda.tracing.submit_errors_metric" )
23912389 @patch ("time.time_ns" , return_value = 42 )
23922390 def test_exception_outside_handler_tracing_enabled (
@@ -2427,7 +2425,7 @@ def test_exception_outside_handler_tracing_enabled(
24272425 assert mock_span .error == 1
24282426 assert mock_span .start_ns == 42
24292427
2430- @patch ("datadog_lambda.tracing.dd_tracing_enabled " , False )
2428+ @patch ("datadog_lambda.config.Config.trace_enabled " , False )
24312429 @patch ("datadog_lambda.tracing.submit_errors_metric" )
24322430 @patch ("time.time_ns" , return_value = 42 )
24332431 def test_exception_outside_handler_tracing_disabled (
0 commit comments