Skip to content

Commit

Permalink
support recursion detection (#4111)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP authored May 31, 2022
1 parent e761018 commit 66ac72f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/feature-util-e4a2f425.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "util",
"description": "set the X-Amzn-Trace-Id header if lambda function name and trace id environmental variables are set"
}
18 changes: 18 additions & 0 deletions lib/event_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ AWS.EventListeners = {
req.httpRequest.headers['Host'] = req.httpRequest.endpoint.host;
});

add('SET_TRACE_ID', 'afterBuild', function SET_TRACE_ID(req) {
var traceIdHeaderName = 'X-Amzn-Trace-Id';
if (AWS.util.isNode() && !Object.hasOwnProperty.call(req.httpRequest.headers, traceIdHeaderName)) {
var ENV_LAMBDA_FUNCTION_NAME = 'AWS_LAMBDA_FUNCTION_NAME';
var ENV_TRACE_ID = '_X_AMZN_TRACE_ID';
var functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
var traceId = process.env[ENV_TRACE_ID];
if (
typeof functionName === 'string' &&
functionName.length > 0 &&
typeof traceId === 'string' &&
traceId.length > 0
) {
req.httpRequest.headers[traceIdHeaderName] = traceId;
}
}
});

add('RESTART', 'restart', function RESTART() {
var err = this.response.error;
if (!err || !err.retryable) return;
Expand Down
52 changes: 52 additions & 0 deletions test/event_listeners.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 66ac72f

Please sign in to comment.