1515from ddtrace ._trace ._span_pointer import _SpanPointer
1616from ddtrace ._trace ._span_pointer import _SpanPointerDirection
1717from ddtrace ._trace ._span_pointer import _SpanPointerDescription
18+ from ddtrace .data_streams import PROPAGATION_KEY_BASE_64
1819
1920from datadog_lambda .constants import (
2021 SamplingPriority ,
@@ -262,6 +263,9 @@ def setUp(self):
262263 self .mock_is_lambda_context = patcher .start ()
263264 self .mock_is_lambda_context .return_value = True
264265 self .addCleanup (patcher .stop )
266+ patcher = patch ("datadog_lambda.config.Config.data_streams_enabled" , True )
267+ self .mock_data_streams_enabled = patcher .start ()
268+ self .addCleanup (patcher .stop )
265269
266270 def tearDown (self ):
267271 del os .environ ["_X_AMZN_TRACE_ID" ]
@@ -2443,46 +2447,53 @@ def test_exception_outside_handler_tracing_disabled(
24432447 mock_trace .assert_not_called ()
24442448
24452449
2446- class TestExtractContextHaveAddedDDContext (unittest .TestCase ):
2450+ class TestExtractContextHaveDSMContext (unittest .TestCase ):
2451+ @patch ("datadog_lambda.config.Config.trace_enabled" , True )
2452+ @patch ("datadog_lambda.config.Config.data_streams_enabled" , True )
24472453 def test_extract_context_from_sqs_event_with_datadog_context (self ):
24482454 """Test SQS event extraction with datadog context returns expected values."""
24492455 lambda_ctx = get_mock_context ()
2450- expected_trace_data = {
2456+ header = {
24512457 TraceHeader .TRACE_ID : "456" ,
24522458 TraceHeader .PARENT_ID : "789" ,
24532459 TraceHeader .SAMPLING_PRIORITY : "1" ,
2460+ PROPAGATION_KEY_BASE_64 : "test-data" ,
24542461 }
2462+
24552463 sqs_event = {
24562464 "Records" : [
24572465 {
24582466 "messageId" : "test-message-id" ,
24592467 "eventSourceARN" : "arn:aws:sqs:us-east-1:123456789012:test-queue" ,
24602468 "messageAttributes" : {
24612469 "_datadog" : {
2462- "stringValue" : json .dumps (expected_trace_data ),
2470+ "stringValue" : json .dumps (header ),
24632471 "dataType" : "String" ,
24642472 }
24652473 },
24662474 }
24672475 ]
24682476 }
24692477
2470- (context , dd_json_data ) = extract_context_from_sqs_or_sns_event_or_context (
2478+ (context , dsm_carrier ) = extract_context_from_sqs_or_sns_event_or_context (
24712479 sqs_event , lambda_ctx
24722480 )
24732481
24742482 self .assertEqual (context .trace_id , 456 )
24752483 self .assertEqual (context .span_id , 789 )
24762484 self .assertEqual (context .sampling_priority , 1 )
2477- self .assertEqual (dd_json_data , expected_trace_data )
2485+ self .assertEqual (dsm_carrier ( PROPAGATION_KEY_BASE_64 ), "test-data" )
24782486
2487+ @patch ("datadog_lambda.config.Config.trace_enabled" , True )
2488+ @patch ("datadog_lambda.config.Config.data_streams_enabled" , True )
24792489 def test_extract_context_from_sns_event_with_datadog_context (self ):
24802490 """Test SNS event extraction with datadog context returns expected values."""
24812491 lambda_ctx = get_mock_context ()
24822492 expected_trace_data = {
24832493 TraceHeader .TRACE_ID : "111" ,
24842494 TraceHeader .PARENT_ID : "222" ,
24852495 TraceHeader .SAMPLING_PRIORITY : "2" ,
2496+ PROPAGATION_KEY_BASE_64 : "test-data" ,
24862497 }
24872498 sns_event = {
24882499 "Records" : [
@@ -2500,21 +2511,24 @@ def test_extract_context_from_sns_event_with_datadog_context(self):
25002511 ]
25012512 }
25022513
2503- (context , dd_json_data ) = extract_context_from_sqs_or_sns_event_or_context (
2514+ (context , dsm_carrier ) = extract_context_from_sqs_or_sns_event_or_context (
25042515 sns_event , lambda_ctx
25052516 )
25062517
25072518 self .assertEqual (context .trace_id , 111 )
25082519 self .assertEqual (context .span_id , 222 )
25092520 self .assertEqual (context .sampling_priority , 2 )
2510- self .assertEqual (dd_json_data , expected_trace_data )
2521+ self .assertEqual (dsm_carrier ( PROPAGATION_KEY_BASE_64 ), "test-data" )
25112522
2523+ @patch ("datadog_lambda.config.Config.trace_enabled" , True )
2524+ @patch ("datadog_lambda.config.Config.data_streams_enabled" , True )
25122525 def test_extract_context_from_kinesis_event_with_datadog_context (self ):
25132526 """Test Kinesis event extraction with datadog context returns expected values."""
25142527 lambda_ctx = get_mock_context ()
25152528 expected_trace_data = {
25162529 TraceHeader .TRACE_ID : "333" ,
25172530 TraceHeader .PARENT_ID : "444" ,
2531+ PROPAGATION_KEY_BASE_64 : "test-data" ,
25182532 }
25192533 kinesis_event = {
25202534 "Records" : [
@@ -2529,50 +2543,24 @@ def test_extract_context_from_kinesis_event_with_datadog_context(self):
25292543 ]
25302544 }
25312545
2532- context , dd_json_data = extract_context_from_kinesis_event (
2546+ context , dsm_carrier = extract_context_from_kinesis_event (
25332547 kinesis_event , lambda_ctx
25342548 )
25352549
25362550 self .assertEqual (context .trace_id , 333 )
25372551 self .assertEqual (context .span_id , 444 )
2538- self .assertEqual (dd_json_data , expected_trace_data )
2539-
2540- def test_step_function_context_in_sqs_calls_step_function_extractor (self ):
2541- """Test that Step Function context in SQS calls the step function extractor."""
2542- lambda_ctx = get_mock_context ()
2543- sfn_context = {
2544- "Execution" : {"Id" : "test-execution-id" },
2545- "StateMachine" : {"Id" : "test-state-machine-id" },
2546- "State" : {"Name" : "test-state" },
2547- }
2548- sfn_sqs_event = {
2549- "Records" : [
2550- {
2551- "eventSourceARN" : "arn:aws:sqs:us-east-1:123456789012:test-queue" ,
2552- "messageAttributes" : {
2553- "_datadog" : {
2554- "stringValue" : json .dumps (sfn_context ),
2555- "dataType" : "String" ,
2556- }
2557- },
2558- }
2559- ]
2560- }
2561-
2562- (context , dd_json_data ) = extract_context_from_sqs_or_sns_event_or_context (
2563- sfn_sqs_event , lambda_ctx
2564- )
2565-
2566- self .assertIsNotNone (context )
2567- self .assertIsNone (dd_json_data )
2552+ self .assertEqual (dsm_carrier (PROPAGATION_KEY_BASE_64 ), "test-data" )
25682553
2554+ @patch ("datadog_lambda.config.Config.trace_enabled" , True )
2555+ @patch ("datadog_lambda.config.Config.data_streams_enabled" , True )
25692556 def test_extract_context_from_sns_to_sqs_event_with_datadog_context (self ):
25702557 """Test SNS -> SQS event extraction with datadog context returns expected values."""
25712558 lambda_ctx = get_mock_context ()
25722559 expected_trace_data = {
25732560 TraceHeader .TRACE_ID : "555" ,
25742561 TraceHeader .PARENT_ID : "666" ,
25752562 TraceHeader .SAMPLING_PRIORITY : "1" ,
2563+ PROPAGATION_KEY_BASE_64 : "test-data" ,
25762564 }
25772565
25782566 sns_body = {
@@ -2599,11 +2587,11 @@ def test_extract_context_from_sns_to_sqs_event_with_datadog_context(self):
25992587 ]
26002588 }
26012589
2602- (context , dd_json_data ) = extract_context_from_sqs_or_sns_event_or_context (
2590+ (context , dsm_carrier ) = extract_context_from_sqs_or_sns_event_or_context (
26032591 sns_to_sqs_event , lambda_ctx
26042592 )
26052593
26062594 self .assertEqual (context .trace_id , 555 )
26072595 self .assertEqual (context .span_id , 666 )
26082596 self .assertEqual (context .sampling_priority , 1 )
2609- self .assertEqual (dd_json_data , expected_trace_data )
2597+ self .assertEqual (dsm_carrier ( PROPAGATION_KEY_BASE_64 ), "test-data" )
0 commit comments