Skip to content

Commit

Permalink
Add route path to request log
Browse files Browse the repository at this point in the history
  • Loading branch information
remvee committed Dec 11, 2024
1 parent 72d0c12 commit 601d329
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions policies/lifecycle-logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@ module.exports = () => {
const reqTimerStart = new Date()
const method = req.method
const url = req.originalUrl

res.on('finish', () => {
const app = req.egContext.app // set by gatekeeper policy
const reqTimerEnd = new Date()
const statusCode = res.statusCode

const infoProps = {
short_message: `${req.traceparent.traceId} - ${method} ${url} ${statusCode}`,
traceparent_trace_id: traceParent.traceId,
traceparent_id: traceParent.id,
traceparent_parent_id: traceParent.parent_id,
client: app,
route_path: req.route && req.route.path,
http_status: statusCode,
request_method: method,
url,
time_ms: reqTimerEnd - reqTimerStart
}

if (res.error_msg) {
// We also use `error_msg` for Bad Gateway errors in
// aggegration policy.
infoProps.error_msg = res.error_msg
}

jsonLog.info(infoProps)
})

next()
}
}

0 comments on commit 601d329

Please sign in to comment.