Skip to content

Commit 66ac72f

Browse files
authored
support recursion detection (#4111)
1 parent e761018 commit 66ac72f

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "util",
4+
"description": "set the X-Amzn-Trace-Id header if lambda function name and trace id environmental variables are set"
5+
}

lib/event_listeners.js

+18
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ AWS.EventListeners = {
211211
req.httpRequest.headers['Host'] = req.httpRequest.endpoint.host;
212212
});
213213

214+
add('SET_TRACE_ID', 'afterBuild', function SET_TRACE_ID(req) {
215+
var traceIdHeaderName = 'X-Amzn-Trace-Id';
216+
if (AWS.util.isNode() && !Object.hasOwnProperty.call(req.httpRequest.headers, traceIdHeaderName)) {
217+
var ENV_LAMBDA_FUNCTION_NAME = 'AWS_LAMBDA_FUNCTION_NAME';
218+
var ENV_TRACE_ID = '_X_AMZN_TRACE_ID';
219+
var functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
220+
var traceId = process.env[ENV_TRACE_ID];
221+
if (
222+
typeof functionName === 'string' &&
223+
functionName.length > 0 &&
224+
typeof traceId === 'string' &&
225+
traceId.length > 0
226+
) {
227+
req.httpRequest.headers[traceIdHeaderName] = traceId;
228+
}
229+
}
230+
});
231+
214232
add('RESTART', 'restart', function RESTART() {
215233
var err = this.response.error;
216234
if (!err || !err.retryable) return;

test/event_listeners.spec.js

+52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)