@@ -493,6 +493,74 @@ def test_kinesis_to_lambda_format(self):
493
493
assert result ["x-datadog-parent-id" ] == "888777666"
494
494
assert result ["dd-pathway-ctx" ] == "test-pathway-ctx"
495
495
496
+ def test_sns_to_sqs_to_lambda_binary_value_format (self ):
497
+ """Test format: message.messageAttributes._datadog.binaryValue.decode() (SNS -> SQS -> lambda, raw)"""
498
+ trace_context = {
499
+ "x-datadog-trace-id" : "777666555" ,
500
+ "x-datadog-parent-id" : "444333222" ,
501
+ "dd-pathway-ctx" : "test-pathway-ctx" ,
502
+ }
503
+ binary_data = base64 .b64encode (
504
+ json .dumps (trace_context ).encode ("utf-8" )
505
+ ).decode ("utf-8" )
506
+
507
+ lambda_record = {
508
+ "messageId" : "test-message-id" ,
509
+ "receiptHandle" : "test-receipt-handle" ,
510
+ "body" : "Test message body" ,
511
+ "messageAttributes" : {
512
+ "_datadog" : {"binaryValue" : binary_data , "dataType" : "Binary" }
513
+ },
514
+ "eventSource" : "aws:sqs" ,
515
+ "eventSourceARN" : "arn:aws:sqs:us-west-2:123456789012:test-queue" ,
516
+ }
517
+
518
+ result = _get_dsm_context_from_lambda (lambda_record )
519
+
520
+ assert result is not None
521
+ assert result == trace_context
522
+ assert result ["x-datadog-trace-id" ] == "777666555"
523
+ assert result ["x-datadog-parent-id" ] == "444333222"
524
+ assert result ["dd-pathway-ctx" ] == "test-pathway-ctx"
525
+
526
+ def test_sns_to_sqs_to_lambda_body_format (self ):
527
+ """Test format: message.body.MessageAttributes._datadog.Value.decode() (SNS -> SQS -> lambda)"""
528
+ trace_context = {
529
+ "x-datadog-trace-id" : "123987456" ,
530
+ "x-datadog-parent-id" : "654321987" ,
531
+ "x-datadog-sampling-priority" : "1" ,
532
+ "dd-pathway-ctx" : "test-pathway-ctx" ,
533
+ }
534
+
535
+ message_body = {
536
+ "Type" : "Notification" ,
537
+ "MessageId" : "test-message-id" ,
538
+ "Message" : "Test message from SNS" ,
539
+ "MessageAttributes" : {
540
+ "_datadog" : {
541
+ "Type" : "Binary" ,
542
+ "Value" : base64 .b64encode (
543
+ json .dumps (trace_context ).encode ("utf-8" )
544
+ ).decode ("utf-8" ),
545
+ }
546
+ },
547
+ }
548
+
549
+ lambda_record = {
550
+ "messageId" : "lambda-message-id" ,
551
+ "body" : json .dumps (message_body ),
552
+ "eventSource" : "aws:sqs" ,
553
+ "eventSourceARN" : "arn:aws:sqs:us-east-1:123456789012:sns-to-sqs-queue" ,
554
+ }
555
+
556
+ result = _get_dsm_context_from_lambda (lambda_record )
557
+
558
+ assert result is not None
559
+ assert result == trace_context
560
+ assert result ["x-datadog-trace-id" ] == "123987456"
561
+ assert result ["x-datadog-parent-id" ] == "654321987"
562
+ assert result ["dd-pathway-ctx" ] == "test-pathway-ctx"
563
+
496
564
def test_no_message_attributes (self ):
497
565
"""Test message without MessageAttributes returns None."""
498
566
message = {
0 commit comments