@@ -667,31 +667,62 @@ describe("readTraceFromLambdaContext", () => {
667
667
} ) ;
668
668
669
669
describe ( "readStepFunctionContextFromEvent" , ( ) => {
670
- const stepFunctionEvent = {
671
- dd : {
672
- Execution : {
673
- Name : "fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492" ,
674
- StartTime : "2019-09-30T20:28:24.236Z" ,
675
- } ,
676
- State : {
677
- Name : "step-one" ,
678
- RetryCount : 2 ,
679
- } ,
680
- StateMachine : {
681
- Id : "arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ" ,
682
- Name : "my-state-machine" ,
683
- } ,
670
+ const stepFunctionEventWithoutInput = {
671
+ Execution : {
672
+ Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
673
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
674
+ RoleArn : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
675
+ StartTime : "2022-12-08T21:08:17.924Z" ,
684
676
} ,
677
+ State : {
678
+ Name : "step-one" ,
679
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
680
+ RetryCount : 2 ,
681
+ } ,
682
+ StateMachine : {
683
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
684
+ Name : "my-state-machine" ,
685
+ } ,
686
+ } as const ;
687
+
688
+ const stepFunctionEvent = {
689
+ ...stepFunctionEventWithoutInput ,
690
+ Execution : {
691
+ ...stepFunctionEventWithoutInput . Execution ,
692
+ Input : {
693
+ MyInput : "MyValue"
694
+ }
695
+ }
685
696
} as const ;
686
- it ( "reads a trace from an execution id" , ( ) => {
697
+
698
+ it ( "reads a step function context from event without Execution.Input" , ( ) => {
699
+ const result = readStepFunctionContextFromEvent ( stepFunctionEventWithoutInput ) ;
700
+ expect ( result ) . toEqual ( {
701
+ "step_function.execution_id" : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
702
+ "step_function.execution_input" : null ,
703
+ "step_function.execution_name" : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
704
+ "step_function.execution_role_arn" : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
705
+ "step_function.execution_start_time" : "2022-12-08T21:08:17.924Z" ,
706
+ "step_function.state_entered_time" : "2022-12-08T21:08:19.224Z" ,
707
+ "step_function.state_machine_arn" : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
708
+ "step_function.state_machine_name" : "my-state-machine" ,
709
+ "step_function.state_name" : "step-one" ,
710
+ "step_function.state_retry_count" : 2 ,
711
+ } ) ;
712
+ } ) ;
713
+ it ( "reads a step function context from event with Execution.Input" , ( ) => {
687
714
const result = readStepFunctionContextFromEvent ( stepFunctionEvent ) ;
688
715
expect ( result ) . toEqual ( {
689
- "step_function.execution_id" : "fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492" ,
690
- "step_function.retry_count" : 2 ,
691
- "step_function.state_machine_arn" :
692
- "arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ" ,
716
+ "step_function.execution_id" : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
717
+ "step_function.execution_input" : { "MyInput" : "MyValue" } ,
718
+ "step_function.execution_name" : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
719
+ "step_function.execution_role_arn" : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
720
+ "step_function.execution_start_time" : "2022-12-08T21:08:17.924Z" ,
721
+ "step_function.state_entered_time" : "2022-12-08T21:08:19.224Z" ,
722
+ "step_function.state_machine_arn" : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
693
723
"step_function.state_machine_name" : "my-state-machine" ,
694
- "step_function.step_name" : "step-one" ,
724
+ "step_function.state_name" : "step-one" ,
725
+ "step_function.state_retry_count" : 2 ,
695
726
} ) ;
696
727
} ) ;
697
728
it ( "returns undefined when event isn't an object" , ( ) => {
@@ -711,7 +742,7 @@ describe("readStepFunctionContextFromEvent", () => {
711
742
it ( "returns undefined when Execution is missing Name field" , ( ) => {
712
743
const result = readStepFunctionContextFromEvent ( {
713
744
dd : {
714
- ...stepFunctionEvent . dd ,
745
+ ...stepFunctionEvent ,
715
746
Execution : { } ,
716
747
} ,
717
748
} ) ;
@@ -720,7 +751,7 @@ describe("readStepFunctionContextFromEvent", () => {
720
751
it ( "returns undefined when Name isn't a string" , ( ) => {
721
752
const result = readStepFunctionContextFromEvent ( {
722
753
dd : {
723
- ...stepFunctionEvent . dd ,
754
+ ...stepFunctionEvent ,
724
755
Execution : {
725
756
Name : 12345 ,
726
757
} ,
@@ -731,7 +762,7 @@ describe("readStepFunctionContextFromEvent", () => {
731
762
it ( "returns undefined when State isn't defined" , ( ) => {
732
763
const result = readStepFunctionContextFromEvent ( {
733
764
dd : {
734
- ...stepFunctionEvent . dd ,
765
+ ...stepFunctionEvent ,
735
766
State : undefined ,
736
767
} ,
737
768
} ) ;
@@ -740,9 +771,9 @@ describe("readStepFunctionContextFromEvent", () => {
740
771
it ( "returns undefined when try retry count isn't a number" , ( ) => {
741
772
const result = readStepFunctionContextFromEvent ( {
742
773
dd : {
743
- ...stepFunctionEvent . dd ,
774
+ ...stepFunctionEvent ,
744
775
State : {
745
- ...stepFunctionEvent . dd . State ,
776
+ ...stepFunctionEvent . State ,
746
777
RetryCount : "1" ,
747
778
} ,
748
779
} ,
@@ -752,9 +783,9 @@ describe("readStepFunctionContextFromEvent", () => {
752
783
it ( "returns undefined when try step name isn't a string" , ( ) => {
753
784
const result = readStepFunctionContextFromEvent ( {
754
785
dd : {
755
- ...stepFunctionEvent . dd ,
786
+ ...stepFunctionEvent ,
756
787
State : {
757
- ...stepFunctionEvent . dd . State ,
788
+ ...stepFunctionEvent . State ,
758
789
Name : 1 ,
759
790
} ,
760
791
} ,
@@ -764,7 +795,7 @@ describe("readStepFunctionContextFromEvent", () => {
764
795
it ( "returns undefined when StateMachine is undefined" , ( ) => {
765
796
const result = readStepFunctionContextFromEvent ( {
766
797
dd : {
767
- ...stepFunctionEvent . dd ,
798
+ ...stepFunctionEvent ,
768
799
StateMachine : undefined ,
769
800
} ,
770
801
} ) ;
@@ -773,9 +804,9 @@ describe("readStepFunctionContextFromEvent", () => {
773
804
it ( "returns undefined when StateMachineId isn't a string" , ( ) => {
774
805
const result = readStepFunctionContextFromEvent ( {
775
806
dd : {
776
- ...stepFunctionEvent . dd ,
807
+ ...stepFunctionEvent ,
777
808
StateMachine : {
778
- ...stepFunctionEvent . dd . StateMachine ,
809
+ ...stepFunctionEvent . StateMachine ,
779
810
Id : 1 ,
780
811
} ,
781
812
} ,
@@ -785,9 +816,9 @@ describe("readStepFunctionContextFromEvent", () => {
785
816
it ( "returns undefined when StateMachineName isn't a string" , ( ) => {
786
817
const result = readStepFunctionContextFromEvent ( {
787
818
dd : {
788
- ...stepFunctionEvent . dd ,
819
+ ...stepFunctionEvent ,
789
820
StateMachine : {
790
- ...stepFunctionEvent . dd . StateMachine ,
821
+ ...stepFunctionEvent . StateMachine ,
791
822
Name : 1 ,
792
823
} ,
793
824
} ,
@@ -1062,21 +1093,26 @@ describe("extractTraceContext", () => {
1062
1093
1063
1094
it ( "adds step function metadata to xray" , ( ) => {
1064
1095
const stepFunctionEvent = {
1065
- dd : {
1066
- Execution : {
1067
- Name : "fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492" ,
1068
- StartTime : "2019-09-30T20:28:24.236Z" ,
1069
- } ,
1070
- State : {
1071
- Name : "step-one" ,
1072
- RetryCount : 2 ,
1073
- } ,
1074
- StateMachine : {
1075
- Id : "arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ" ,
1076
- Name : "my-state-machine" ,
1077
- } ,
1078
- } ,
1079
- } as const ;
1096
+ Execution : {
1097
+ Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
1098
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
1099
+ RoleArn : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
1100
+ StartTime : "2022-12-08T21:08:17.924Z" ,
1101
+ Input : {
1102
+ MyInput : "MyValue"
1103
+ }
1104
+ } ,
1105
+ State : {
1106
+ Name : "step-one" ,
1107
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
1108
+ RetryCount : 2 ,
1109
+ } ,
1110
+ StateMachine : {
1111
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
1112
+ Name : "my-state-machine" ,
1113
+ } ,
1114
+ } as const ;
1115
+
1080
1116
jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => 1487076708000 ) ;
1081
1117
process . env [ xrayTraceEnvVar ] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1" ;
1082
1118
process . env [ awsXrayDaemonAddressEnvVar ] = "localhost:127.0.0.1:2000" ;
@@ -1089,7 +1125,7 @@ describe("extractTraceContext", () => {
1089
1125
const sentMessage = sentSegment . toString ( ) ;
1090
1126
expect ( sentMessage ) . toMatchInlineSnapshot ( `
1091
1127
"{\\"format\\": \\"json\\", \\"version\\": 1}
1092
- {\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708,\\"end_time\\":1487076708,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"root_span_metadata\\":{\\"step_function.execution_id\\":\\"fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492\\",\\"step_function.retry_count\\":2,\\"step_function.state_machine_arn\\":\\"arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ\\",\\"step_function.state_machine_name\\":\\"my-state-machine\\",\\"step_function.step_name\\":\\"step-one\\"}}}}"
1128
+ {\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708,\\"end_time\\":1487076708,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"root_span_metadata\\":{\\"step_function.execution_name\\":\\"85a9933e-9e11-83dc-6a61-b92367b6c3be\\",\\"step_function.execution_id\\":\\"arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf\\",\\"step_function.execution_input\\":{\\"MyInput\\":\\"MyValue\\"},\\"step_function.execution_role_arn\\":\\"arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03\\",\\"step_function.execution_start_time\\":\\"2022-12-08T21:08:17.924Z\\",\\"step_function.state_entered_time\\":\\"2022-12-08T21:08:19.224Z\\",\\"step_function.state_machine_arn\\":\\"arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential\\",\\"step_function.state_machine_name\\":\\"my-state-machine\\",\\"step_function.state_name\\":\\"step-one\\",\\"step_function.state_retry_count\\":2}}}}"
1093
1129
` ) ;
1094
1130
} ) ;
1095
1131
} ) ;
0 commit comments