Skip to content

Commit

Permalink
log request_id if header is set by heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed Aug 5, 2017
1 parent e1fa2b8 commit f2c3cca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion jobQueue/jobWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TIME_TO_LIVE =

/**
* Set log object params from job results.
*
* @param {Object} jobResultObj - Job result object
* @param {Object} logObject - Log object
*/
Expand Down Expand Up @@ -117,9 +118,13 @@ function logJobOnComplete(req, job) {

/*
* If req object is defined; extract the user name, token and ipaddress and
* update the log object
* update the log object. Add "request_id" if header is set by heroku.
*/
if (req) {
if (req.headers && req.headers['x-request-id']) {
logObject.request_id = req.headers['x-request-id'];
}

logObject.ipAddress = activityLogUtil.getIPAddrFromReq(req);
jwtUtil.getTokenDetailsFromRequest(req)
.then((resObj) => {
Expand Down
8 changes: 6 additions & 2 deletions utils/apiLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ function logAPI(req, resultObj, retval, recordCountOverride) {
method: req.method,
};

// if API token enabled,
// extract user, token to update log object
// Add "request_id" if header is set by heroku.
if (req.headers && req.headers['x-request-id']) {
logObject.request_id = req.headers['x-request-id'];
}

// If API token enabled, extract user, token to update log object
jwtUtil.getTokenDetailsFromRequest(req)
.then((resObj) => {
logObject.user = resObj.username;
Expand Down

0 comments on commit f2c3cca

Please sign in to comment.