@@ -6,6 +6,7 @@ import { Sha256 } from "@aws-crypto/sha256-js";
6
6
interface NestedStepFunctionContext {
7
7
execution_id : string ;
8
8
redrive_count : string ;
9
+ retry_count : string ;
9
10
state_entered_time : string ;
10
11
state_name : string ;
11
12
root_execution_id : string ;
@@ -15,6 +16,7 @@ interface NestedStepFunctionContext {
15
16
interface LambdaRootStepFunctionContext {
16
17
execution_id : string ;
17
18
redrive_count : string ;
19
+ retry_count : string ;
18
20
state_entered_time : string ;
19
21
state_name : string ;
20
22
trace_id : string ;
@@ -25,6 +27,7 @@ interface LambdaRootStepFunctionContext {
25
27
interface LegacyStepFunctionContext {
26
28
execution_id : string ;
27
29
redrive_count : string ;
30
+ retry_count : string ;
28
31
state_entered_time : string ;
29
32
state_name : string ;
30
33
}
@@ -91,13 +94,14 @@ export class StepFunctionContextService {
91
94
// Extract the common context variables
92
95
const stateMachineContext = this . extractStateMachineContext ( event ) ;
93
96
if ( stateMachineContext === null ) return ;
94
- const { execution_id, redrive_count, state_entered_time, state_name } = stateMachineContext ;
97
+ const { execution_id, redrive_count, retry_count , state_entered_time, state_name } = stateMachineContext ;
95
98
96
99
if ( typeof event [ "serverless-version" ] === "string" && event [ "serverless-version" ] === "v1" ) {
97
100
if ( typeof event . RootExecutionId === "string" ) {
98
101
this . context = {
99
102
execution_id,
100
103
redrive_count,
104
+ retry_count,
101
105
state_entered_time,
102
106
state_name,
103
107
root_execution_id : event . RootExecutionId ,
@@ -107,6 +111,7 @@ export class StepFunctionContextService {
107
111
this . context = {
108
112
execution_id,
109
113
redrive_count,
114
+ retry_count,
110
115
state_entered_time,
111
116
state_name,
112
117
trace_id : event [ "x-datadog-trace-id" ] ,
@@ -115,7 +120,13 @@ export class StepFunctionContextService {
115
120
} as LambdaRootStepFunctionContext ;
116
121
}
117
122
} else {
118
- this . context = { execution_id, redrive_count, state_entered_time, state_name } as LegacyStepFunctionContext ;
123
+ this . context = {
124
+ execution_id,
125
+ redrive_count,
126
+ retry_count,
127
+ state_entered_time,
128
+ state_name,
129
+ } as LegacyStepFunctionContext ;
119
130
}
120
131
}
121
132
@@ -139,17 +150,16 @@ export class StepFunctionContextService {
139
150
return null ;
140
151
}
141
152
142
- const redrivePostfix = this . context . redrive_count === "0" ? "" : `#${ this . context . redrive_count } ` ;
153
+ const countsSuffix =
154
+ this . context . retry_count !== "0" || this . context . redrive_count !== "0"
155
+ ? `#${ this . context . retry_count } #${ this . context . redrive_count } `
156
+ : "" ;
143
157
144
158
const parentId = this . deterministicSha256HashToBigIntString (
145
- this . context . execution_id +
146
- "#" +
147
- this . context . state_name +
148
- "#" +
149
- this . context . state_entered_time +
150
- redrivePostfix ,
159
+ `${ this . context . execution_id } #${ this . context . state_name } #${ this . context . state_entered_time } ${ countsSuffix } ` ,
151
160
PARENT_ID ,
152
161
) ;
162
+
153
163
const sampleMode = SampleMode . AUTO_KEEP ;
154
164
155
165
try {
@@ -209,13 +219,15 @@ export class StepFunctionContextService {
209
219
private extractStateMachineContext ( event : any ) : {
210
220
execution_id : string ;
211
221
redrive_count : string ;
222
+ retry_count : string ;
212
223
state_entered_time : string ;
213
224
state_name : string ;
214
225
} | null {
215
226
if ( this . isValidContextObject ( event ) ) {
216
227
return {
217
228
execution_id : event . Execution . Id ,
218
229
redrive_count : ( event . Execution . RedriveCount ?? "0" ) . toString ( ) ,
230
+ retry_count : ( event . State . RetryCount ?? "0" ) . toString ( ) ,
219
231
state_entered_time : event . State . EnteredTime ,
220
232
state_name : event . State . Name ,
221
233
} ;
0 commit comments