@@ -668,30 +668,41 @@ describe("readTraceFromLambdaContext", () => {
668
668
669
669
describe ( "readStepFunctionContextFromEvent" , ( ) => {
670
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" ,
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
+ Input : {
674
+ MyInput : "MyValue" ,
683
675
} ,
676
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
677
+ RoleArn : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
678
+ StartTime : "2022-12-08T21:08:17.924Z" ,
679
+ } ,
680
+ State : {
681
+ Name : "step-one" ,
682
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
683
+ RetryCount : 2 ,
684
+ } ,
685
+ StateMachine : {
686
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
687
+ Name : "my-state-machine" ,
684
688
} ,
685
689
} as const ;
686
- it ( "reads a trace from an execution id" , ( ) => {
690
+
691
+ it ( "reads a step function context from event with Execution.Input" , ( ) => {
687
692
const result = readStepFunctionContextFromEvent ( stepFunctionEvent ) ;
688
693
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" ,
694
+ "step_function.execution_id" :
695
+ "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
696
+ "step_function.execution_input" : { MyInput : "MyValue" } ,
697
+ "step_function.execution_name" : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
698
+ "step_function.execution_role_arn" :
699
+ "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
700
+ "step_function.execution_start_time" : "2022-12-08T21:08:17.924Z" ,
701
+ "step_function.state_entered_time" : "2022-12-08T21:08:19.224Z" ,
702
+ "step_function.state_machine_arn" : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
693
703
"step_function.state_machine_name" : "my-state-machine" ,
694
- "step_function.step_name" : "step-one" ,
704
+ "step_function.state_name" : "step-one" ,
705
+ "step_function.state_retry_count" : 2 ,
695
706
} ) ;
696
707
} ) ;
697
708
it ( "returns undefined when event isn't an object" , ( ) => {
@@ -711,7 +722,7 @@ describe("readStepFunctionContextFromEvent", () => {
711
722
it ( "returns undefined when Execution is missing Name field" , ( ) => {
712
723
const result = readStepFunctionContextFromEvent ( {
713
724
dd : {
714
- ...stepFunctionEvent . dd ,
725
+ ...stepFunctionEvent ,
715
726
Execution : { } ,
716
727
} ,
717
728
} ) ;
@@ -720,7 +731,7 @@ describe("readStepFunctionContextFromEvent", () => {
720
731
it ( "returns undefined when Name isn't a string" , ( ) => {
721
732
const result = readStepFunctionContextFromEvent ( {
722
733
dd : {
723
- ...stepFunctionEvent . dd ,
734
+ ...stepFunctionEvent ,
724
735
Execution : {
725
736
Name : 12345 ,
726
737
} ,
@@ -731,7 +742,7 @@ describe("readStepFunctionContextFromEvent", () => {
731
742
it ( "returns undefined when State isn't defined" , ( ) => {
732
743
const result = readStepFunctionContextFromEvent ( {
733
744
dd : {
734
- ...stepFunctionEvent . dd ,
745
+ ...stepFunctionEvent ,
735
746
State : undefined ,
736
747
} ,
737
748
} ) ;
@@ -740,9 +751,9 @@ describe("readStepFunctionContextFromEvent", () => {
740
751
it ( "returns undefined when try retry count isn't a number" , ( ) => {
741
752
const result = readStepFunctionContextFromEvent ( {
742
753
dd : {
743
- ...stepFunctionEvent . dd ,
754
+ ...stepFunctionEvent ,
744
755
State : {
745
- ...stepFunctionEvent . dd . State ,
756
+ ...stepFunctionEvent . State ,
746
757
RetryCount : "1" ,
747
758
} ,
748
759
} ,
@@ -752,9 +763,9 @@ describe("readStepFunctionContextFromEvent", () => {
752
763
it ( "returns undefined when try step name isn't a string" , ( ) => {
753
764
const result = readStepFunctionContextFromEvent ( {
754
765
dd : {
755
- ...stepFunctionEvent . dd ,
766
+ ...stepFunctionEvent ,
756
767
State : {
757
- ...stepFunctionEvent . dd . State ,
768
+ ...stepFunctionEvent . State ,
758
769
Name : 1 ,
759
770
} ,
760
771
} ,
@@ -764,7 +775,7 @@ describe("readStepFunctionContextFromEvent", () => {
764
775
it ( "returns undefined when StateMachine is undefined" , ( ) => {
765
776
const result = readStepFunctionContextFromEvent ( {
766
777
dd : {
767
- ...stepFunctionEvent . dd ,
778
+ ...stepFunctionEvent ,
768
779
StateMachine : undefined ,
769
780
} ,
770
781
} ) ;
@@ -773,9 +784,9 @@ describe("readStepFunctionContextFromEvent", () => {
773
784
it ( "returns undefined when StateMachineId isn't a string" , ( ) => {
774
785
const result = readStepFunctionContextFromEvent ( {
775
786
dd : {
776
- ...stepFunctionEvent . dd ,
787
+ ...stepFunctionEvent ,
777
788
StateMachine : {
778
- ...stepFunctionEvent . dd . StateMachine ,
789
+ ...stepFunctionEvent . StateMachine ,
779
790
Id : 1 ,
780
791
} ,
781
792
} ,
@@ -785,9 +796,9 @@ describe("readStepFunctionContextFromEvent", () => {
785
796
it ( "returns undefined when StateMachineName isn't a string" , ( ) => {
786
797
const result = readStepFunctionContextFromEvent ( {
787
798
dd : {
788
- ...stepFunctionEvent . dd ,
799
+ ...stepFunctionEvent ,
789
800
StateMachine : {
790
- ...stepFunctionEvent . dd . StateMachine ,
801
+ ...stepFunctionEvent . StateMachine ,
791
802
Name : 1 ,
792
803
} ,
793
804
} ,
@@ -1062,21 +1073,26 @@ describe("extractTraceContext", () => {
1062
1073
1063
1074
it ( "adds step function metadata to xray" , ( ) => {
1064
1075
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" ,
1076
+ Execution : {
1077
+ Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
1078
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
1079
+ RoleArn : "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
1080
+ StartTime : "2022-12-08T21:08:17.924Z" ,
1081
+ Input : {
1082
+ MyInput : "MyValue" ,
1077
1083
} ,
1078
1084
} ,
1085
+ State : {
1086
+ Name : "step-one" ,
1087
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
1088
+ RetryCount : 2 ,
1089
+ } ,
1090
+ StateMachine : {
1091
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
1092
+ Name : "my-state-machine" ,
1093
+ } ,
1079
1094
} as const ;
1095
+
1080
1096
jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => 1487076708000 ) ;
1081
1097
process . env [ xrayTraceEnvVar ] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1" ;
1082
1098
process . env [ awsXrayDaemonAddressEnvVar ] = "localhost:127.0.0.1:2000" ;
@@ -1089,7 +1105,7 @@ describe("extractTraceContext", () => {
1089
1105
const sentMessage = sentSegment . toString ( ) ;
1090
1106
expect ( sentMessage ) . toMatchInlineSnapshot ( `
1091
1107
"{\\"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\\"}}}}"
1108
+ {\\"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
1109
` ) ;
1094
1110
} ) ;
1095
1111
} ) ;
0 commit comments