|
|
|
@ -5,15 +5,19 @@ const MAX_LENGTH = 100;
|
|
|
|
|
|
|
|
|
|
function pubSubMetrics (pubSubMetricsBackend) {
|
|
|
|
|
if (!pubSubMetricsBackend.isEnabled()) {
|
|
|
|
|
return function pubSubMetricsDisabledMiddleware (req, res, next) { next(); };
|
|
|
|
|
return function pubSubMetricsDisabledMiddleware (req, res, next) {
|
|
|
|
|
next();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function pubSubMetricsMiddleware (req, res, next) {
|
|
|
|
|
const data = getEventData(req, res);
|
|
|
|
|
res.on('finish', () => {
|
|
|
|
|
const { event, attributes } = getEventData(req, res);
|
|
|
|
|
|
|
|
|
|
if (data.event) {
|
|
|
|
|
pubSubMetricsBackend.sendEvent(data.event, data.attributes);
|
|
|
|
|
}
|
|
|
|
|
if (event) {
|
|
|
|
|
pubSubMetricsBackend.sendEvent(event, attributes);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
};
|
|
|
|
|