File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
packages/middleware-recursion-detection/src Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -22,22 +22,22 @@ interface PreviouslyResolved {
22
22
* Inject to trace ID to request header to detect recursion invocation in Lambda.
23
23
* @internal
24
24
*/
25
- export function recursionDetectionMiddleware ( options : PreviouslyResolved ) : BuildMiddleware < any , any > {
26
- return < Output extends MetadataBearer > ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
25
+ const recursionDetectionMiddleware = ( options : PreviouslyResolved ) : BuildMiddleware < any , any > =>
26
+ ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
27
27
async ( args : BuildHandlerArguments < any > ) : Promise < BuildHandlerOutput < Output > > => {
28
28
const { request } = args ;
29
- if ( ! HttpRequest . isInstance ( request ) || options . runtime !== "node" ) {
29
+ if (
30
+ ! HttpRequest . isInstance ( request ) ||
31
+ options . runtime !== "node" ||
32
+ request . headers . hasOwnProperty ( TRACE_ID_HEADER_NAME )
33
+ ) {
30
34
return next ( args ) ;
31
35
}
32
36
33
37
const functionName = process . env [ ENV_LAMBDA_FUNCTION_NAME ] ;
34
38
const traceId = process . env [ ENV_TRACE_ID ] ;
35
39
const nonEmptyString = ( str : unknown ) : str is string => typeof str === "string" && str . length > 0 ;
36
- if (
37
- ! request . headers . hasOwnProperty ( TRACE_ID_HEADER_NAME ) &&
38
- nonEmptyString ( functionName ) &&
39
- nonEmptyString ( traceId )
40
- ) {
40
+ if ( nonEmptyString ( functionName ) && nonEmptyString ( traceId ) ) {
41
41
request . headers [ TRACE_ID_HEADER_NAME ] = traceId ;
42
42
}
43
43
return next ( {
You can’t perform that action at this time.
0 commit comments