diff --git a/src/middleware/req-logging.js b/src/middleware/req-logging.js index 914b14d..34b43bc 100644 --- a/src/middleware/req-logging.js +++ b/src/middleware/req-logging.js @@ -40,7 +40,7 @@ const logReqInfo = function (req, res, next) { body: req.body } - wlogger.verbose(`Request: ${ip} ${method} ${url}`, dataToLog) + wlogger.info(`Request: ${ip} ${method} ${url}`, dataToLog) next() } catch (err) { diff --git a/src/middleware/route-ratelimit.js b/src/middleware/route-ratelimit.js index c90e03a..ee2f20c 100644 --- a/src/middleware/route-ratelimit.js +++ b/src/middleware/route-ratelimit.js @@ -1,6 +1,4 @@ /* -This file will replace the original rate-limit.js file. - Sets the rate limits for the anonymous and paid tiers. Current rate limits: - 10000 points in 60 seconds - 500 points per call for anonymous tier (20 RPM) @@ -258,6 +256,15 @@ class RateLimits { // const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume) // console.log(`rateLimitData: `, rateLimitData) + // Add data to logs for analytics. + const logData = { + ip: req.ip, + key, + pointsToConsume, + status: 'OK' + } + wlogger.info(logData) + res.locals.pointsToConsume = pointsToConsume // Feedback for tests. // Signal that the user has not exceeded their rate limits. @@ -274,6 +281,15 @@ class RateLimits { // `rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}` // ) + // Add data to logs for analytics. + const logData = { + ip: req.ip, + key, + pointsToConsume, + status: 429 + } + wlogger.info(logData) + // Rate limited was triggered res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330 return res.json({