mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Revert "reduce memory capture in http logger"
This reverts commit fc2e043b20204e04f240814d4efc05762db7df96. Had to revert this because req.route.path is not set until a matching route has been hit, so it was always null inside res.end meaning statsd data was never sent over. This commit did not actually stop the memory leak so reverting it has not short term repocusion
This commit is contained in:
parent
1e0a991fcd
commit
9329249bc9
1 changed files with 9 additions and 21 deletions
|
@ -4,35 +4,23 @@ module.exports.monitor = (logger) ->
|
||||||
return (req, res, next) ->
|
return (req, res, next) ->
|
||||||
Metrics = require("./metrics")
|
Metrics = require("./metrics")
|
||||||
startTime = new Date()
|
startTime = new Date()
|
||||||
|
|
||||||
# only capture the properties of 'req' that we need, to avoid
|
|
||||||
# leaking the whole req object for responses that never call
|
|
||||||
# res.end()
|
|
||||||
url = req.originalUrl || req.url
|
|
||||||
method = req.method
|
|
||||||
referrer = req.headers['referer'] || req.headers['referrer']
|
|
||||||
remoteAddr = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
|
|
||||||
userAgent = req.headers["user-agent"]
|
|
||||||
contentLength = req.headers["content-length"]
|
|
||||||
path = req.route?.path
|
|
||||||
|
|
||||||
end = res.end
|
end = res.end
|
||||||
res.end = () ->
|
res.end = () ->
|
||||||
end.apply(this, arguments)
|
end.apply(this, arguments)
|
||||||
responseTime = new Date() - startTime
|
responseTime = new Date() - startTime
|
||||||
if path?
|
if req.route?.path?
|
||||||
routePath = path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1)
|
routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1)
|
||||||
key = "http-requests.#{routePath}.#{method}.#{res.statusCode}"
|
key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}"
|
||||||
|
|
||||||
Metrics.timing(key, responseTime)
|
Metrics.timing(key, responseTime)
|
||||||
logger.log
|
logger.log
|
||||||
req:
|
req:
|
||||||
url: url
|
url: req.originalUrl || req.url
|
||||||
method: method
|
method: req.method
|
||||||
referrer: referrer
|
referrer: req.headers['referer'] || req.headers['referrer']
|
||||||
"remote-addr": remoteAddr
|
"remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
|
||||||
"user-agent": userAgent
|
"user-agent": req.headers["user-agent"]
|
||||||
"content-length": contentLength
|
"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
|
||||||
|
|
Loading…
Reference in a new issue