@@ -874,8 +874,8 @@ describe("TraceContextExtractor", () => {
874
874
expect ( extractor ) . toBeInstanceOf ( _class ) ;
875
875
} ) ;
876
876
877
- it ( "returns StepFunctionEventTraceExtractor when event contains StepFunctionContext " , ( ) => {
878
- const event = {
877
+ it ( "returns StepFunctionEventTraceExtractor when event contains LegacyStepFunctionContext " , ( ) => {
878
+ const legacyStepFunctionEvent = {
879
879
Execution : {
880
880
Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
881
881
Input : {
@@ -900,10 +900,90 @@ describe("TraceContextExtractor", () => {
900
900
const traceContextExtractor = new TraceContextExtractor ( tracerWrapper , { } as TraceConfig ) ;
901
901
902
902
// Mimick TraceContextService.extract initialization
903
- const instance = StepFunctionContextService . instance ( event ) ;
903
+ const instance = StepFunctionContextService . instance ( legacyStepFunctionEvent ) ;
904
904
traceContextExtractor [ "stepFunctionContextService" ] = instance ;
905
905
906
- const extractor = traceContextExtractor [ "getTraceEventExtractor" ] ( event ) ;
906
+ const extractor = traceContextExtractor [ "getTraceEventExtractor" ] ( legacyStepFunctionEvent ) ;
907
+
908
+ expect ( extractor ) . toBeInstanceOf ( StepFunctionEventTraceExtractor ) ;
909
+ } ) ;
910
+
911
+ it ( "returns StepFunctionEventTraceExtractor when event contains LambdaRootStepFunctionContext" , ( ) => {
912
+ const lambdaRootStepFunctionEvent = {
913
+ _datadog : {
914
+ Execution : {
915
+ Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
916
+ Input : {
917
+ MyInput : "MyValue" ,
918
+ } ,
919
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
920
+ RoleArn :
921
+ "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
922
+ StartTime : "2022-12-08T21:08:17.924Z" ,
923
+ } ,
924
+ State : {
925
+ Name : "step-one" ,
926
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
927
+ RetryCount : 2 ,
928
+ } ,
929
+ StateMachine : {
930
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
931
+ Name : "my-state-machine" ,
932
+ } ,
933
+ "x-datadog-trace-id" : "10593586103637578129" ,
934
+ "x-datadog-tags" : "_dd.p.dm=-0,_dd.p.tid=6734e7c300000000" ,
935
+ "serverless-version" : "v1" ,
936
+ } ,
937
+ } ;
938
+
939
+ const tracerWrapper = new TracerWrapper ( ) ;
940
+ const traceContextExtractor = new TraceContextExtractor ( tracerWrapper , { } as TraceConfig ) ;
941
+
942
+ // Mimick TraceContextService.extract initialization
943
+ const instance = StepFunctionContextService . instance ( lambdaRootStepFunctionEvent ) ;
944
+ traceContextExtractor [ "stepFunctionContextService" ] = instance ;
945
+
946
+ const extractor = traceContextExtractor [ "getTraceEventExtractor" ] ( lambdaRootStepFunctionEvent ) ;
947
+
948
+ expect ( extractor ) . toBeInstanceOf ( StepFunctionEventTraceExtractor ) ;
949
+ } ) ;
950
+
951
+ it ( "returns StepFunctionEventTraceExtractor when event contains NestedStepFunctionContext" , ( ) => {
952
+ const nestedStepFunctionEvent = {
953
+ _datadog : {
954
+ Execution : {
955
+ Id : "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf" ,
956
+ Input : {
957
+ MyInput : "MyValue" ,
958
+ } ,
959
+ Name : "85a9933e-9e11-83dc-6a61-b92367b6c3be" ,
960
+ RoleArn :
961
+ "arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03" ,
962
+ StartTime : "2022-12-08T21:08:17.924Z" ,
963
+ } ,
964
+ State : {
965
+ Name : "step-one" ,
966
+ EnteredTime : "2022-12-08T21:08:19.224Z" ,
967
+ RetryCount : 2 ,
968
+ } ,
969
+ StateMachine : {
970
+ Id : "arn:aws:states:sa-east-1:425362996713:stateMachine:logs-to-traces-sequential" ,
971
+ Name : "my-state-machine" ,
972
+ } ,
973
+ RootExecutionId :
974
+ "arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:a1b2c3d4-e5f6-7890-1234-56789abcdef0:9f8e7d6c-5b4a-3c2d-1e0f-123456789abc" ,
975
+ "serverless-version" : "v1" ,
976
+ } ,
977
+ } ;
978
+
979
+ const tracerWrapper = new TracerWrapper ( ) ;
980
+ const traceContextExtractor = new TraceContextExtractor ( tracerWrapper , { } as TraceConfig ) ;
981
+
982
+ // Mimick TraceContextService.extract initialization
983
+ const instance = StepFunctionContextService . instance ( nestedStepFunctionEvent ) ;
984
+ traceContextExtractor [ "stepFunctionContextService" ] = instance ;
985
+
986
+ const extractor = traceContextExtractor [ "getTraceEventExtractor" ] ( nestedStepFunctionEvent ) ;
907
987
908
988
expect ( extractor ) . toBeInstanceOf ( StepFunctionEventTraceExtractor ) ;
909
989
} ) ;
@@ -946,7 +1026,7 @@ describe("TraceContextExtractor", () => {
946
1026
} ) ;
947
1027
} ) ;
948
1028
949
- describe ( "addTraceContexToXray " , ( ) => {
1029
+ describe ( "addTraceContextToXray " , ( ) => {
950
1030
beforeEach ( ( ) => {
951
1031
StepFunctionContextService [ "_instance" ] = undefined as any ;
952
1032
sentSegment = undefined ;
@@ -955,7 +1035,7 @@ describe("TraceContextExtractor", () => {
955
1035
process . env [ "AWS_XRAY_DAEMON_ADDRESS" ] = undefined ;
956
1036
} ) ;
957
1037
958
- it ( "adds StepFunction context when present over metadata" , ( ) => {
1038
+ it ( "adds legacy StepFunction context when present over metadata" , ( ) => {
959
1039
jest . spyOn ( Date , "now" ) . mockImplementation ( ( ) => 1487076708000 ) ;
960
1040
961
1041
process . env [ "_X_AMZN_TRACE_ID" ] = "Root=1-5e272390-8c398be037738dc042009320;Parent=94ae789b969f1cc5;Sampled=1" ;
@@ -1006,7 +1086,7 @@ describe("TraceContextExtractor", () => {
1006
1086
1007
1087
const sentMessage = sentSegment . toString ( ) ;
1008
1088
expect ( sentMessage ) . toEqual (
1009
- '{"format": "json", "version": 1}\n{"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}}}}' ,
1089
+ '{"format": "json", "version": 1}\n{"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":{"execution_id":"arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:85a9933e-9e11-83dc-6a61-b92367b6c3be:3f7ef5c7-c8b8-4c88-90a1-d54aa7e7e2bf","state_entered_time":"2022-12-08T21:08:19.224Z","state_name":"step-one"}}}}' ,
1010
1090
) ;
1011
1091
} ) ;
1012
1092
0 commit comments