Log requests that don't have a route property

The v1 history service has its routes set up via swagger-tools, which
doesn't write a route property on the request. This prevents us to send
request metrics based on the route, but we can still log the request.
This commit is contained in:
Eric Mc Sween 2020-07-03 16:38:29 -04:00
parent ea435c88ea
commit d69195eaa9

View file

@ -18,36 +18,36 @@ module.exports.monitor = (logger) ->
Metrics.timing("http_request", responseTimeMs, null, {method:req.method, status_code: res.statusCode, path:routePath}) Metrics.timing("http_request", responseTimeMs, null, {method:req.method, status_code: res.statusCode, path:routePath})
if requestSize if requestSize
Metrics.summary("http_request_size_bytes", requestSize, {method:req.method, status_code: res.statusCode, path:routePath}) Metrics.summary("http_request_size_bytes", requestSize, {method:req.method, status_code: res.statusCode, path:routePath})
remoteIp = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress remoteIp = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
reqUrl = req.originalUrl || req.url reqUrl = req.originalUrl || req.url
referrer = req.headers['referer'] || req.headers['referrer'] referrer = req.headers['referer'] || req.headers['referrer']
if STACKDRIVER_LOGGING if STACKDRIVER_LOGGING
info = info =
httpRequest: httpRequest:
requestMethod: req.method requestMethod: req.method
requestUrl: reqUrl requestUrl: reqUrl
requestSize: requestSize requestSize: requestSize
status: res.statusCode status: res.statusCode
responseSize: res._headers?["content-length"] responseSize: res._headers?["content-length"]
userAgent: req.headers["user-agent"] userAgent: req.headers["user-agent"]
remoteIp: remoteIp remoteIp: remoteIp
referer: referrer referer: referrer
latency: latency:
seconds: responseTime[0] seconds: responseTime[0]
nanos: responseTime[1] nanos: responseTime[1]
protocol: req.protocol protocol: req.protocol
else else
info = info =
req: req:
url: reqUrl url: reqUrl
method: req.method method: req.method
referrer: referrer referrer: referrer
"remote-addr": remoteIp "remote-addr": remoteIp
"user-agent": req.headers["user-agent"] "user-agent": req.headers["user-agent"]
"content-length": req.headers["content-length"] "content-length": req.headers["content-length"]
res: res:
"content-length": res._headers?["content-length"] "content-length": res._headers?["content-length"]
statusCode: res.statusCode statusCode: res.statusCode
"response-time": responseTimeMs "response-time": responseTimeMs
logger.info(info, "%s %s", req.method, reqUrl) logger.info(info, "%s %s", req.method, reqUrl)
next() next()