2021-02-16 14:30:08 +01:00
|
|
|
import * as responseTime from 'response-time';
|
|
|
|
import { REQUEST_TIME } from '../events';
|
2017-11-16 15:41:33 +01:00
|
|
|
|
2021-02-16 14:30:08 +01:00
|
|
|
var _responseTime = responseTime.default
|
2017-11-16 15:41:33 +01:00
|
|
|
|
2021-02-16 14:30:08 +01:00
|
|
|
export function responseTimeMetrics(config) {
|
|
|
|
return _responseTime((req, res, time) => {
|
2020-04-30 23:04:06 +02:00
|
|
|
const { statusCode } = res;
|
2021-02-15 13:04:56 +01:00
|
|
|
|
|
|
|
const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)';
|
2020-04-30 23:04:06 +02:00
|
|
|
|
2017-11-16 15:41:33 +01:00
|
|
|
const timingInfo = {
|
2017-12-18 15:12:44 +01:00
|
|
|
path: pathname,
|
2017-11-16 15:41:33 +01:00
|
|
|
method: req.method,
|
2020-04-30 23:04:06 +02:00
|
|
|
statusCode,
|
2017-11-16 15:41:33 +01:00
|
|
|
time,
|
|
|
|
};
|
|
|
|
config.eventBus.emit(REQUEST_TIME, timingInfo);
|
|
|
|
});
|
|
|
|
};
|