Skip to content

Commit

Permalink
add request timing logging to condenser
Browse files Browse the repository at this point in the history
  • Loading branch information
jredbeard committed May 17, 2017
1 parent a1d0629 commit a00a684
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/requesttimings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = requestTime;

function requestTime() {
return function *requestTime(next) {
let start = Date.now();
yield* next;
let delta = Math.ceil(Date.now() - start);
// log all requests that take longer than 150ms
if(delta > 150)
console.log('Request took too long! ' + delta + 'ms: ' + this.request.method + ' ' + this.request.path);
}
}
3 changes: 3 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Koa from 'koa';
import mount from 'koa-mount';
import helmet from 'koa-helmet';
import koa_logger from 'koa-logger';
import requestTime from './requesttimings';
import prod_logger from './prod_logger';
import favicon from 'koa-favicon';
import staticCache from 'koa-static-cache';
Expand Down Expand Up @@ -40,6 +41,8 @@ const env = process.env.NODE_ENV || 'development';
// cache of a thousand days
const cacheOpts = { maxAge: 86400000, gzip: true };

app.use(requestTime());

app.keys = [config.get('session_key')];

const crypto_key = config.get('server_session_secret');
Expand Down

0 comments on commit a00a684

Please sign in to comment.