Send pubsub metrics once the response has finished
This commit is contained in:
parent
3cec6b5a90
commit
42dc2915ea
@ -5,15 +5,19 @@ const MAX_LENGTH = 100;
|
|||||||
|
|
||||||
function pubSubMetrics (pubSubMetricsBackend) {
|
function pubSubMetrics (pubSubMetricsBackend) {
|
||||||
if (!pubSubMetricsBackend.isEnabled()) {
|
if (!pubSubMetricsBackend.isEnabled()) {
|
||||||
return function pubSubMetricsDisabledMiddleware (req, res, next) { next(); };
|
return function pubSubMetricsDisabledMiddleware (req, res, next) {
|
||||||
|
next();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return function pubSubMetricsMiddleware (req, res, next) {
|
return function pubSubMetricsMiddleware (req, res, next) {
|
||||||
const data = getEventData(req, res);
|
res.on('finish', () => {
|
||||||
|
const { event, attributes } = getEventData(req, res);
|
||||||
|
|
||||||
if (data.event) {
|
if (event) {
|
||||||
pubSubMetricsBackend.sendEvent(data.event, data.attributes);
|
pubSubMetricsBackend.sendEvent(event, attributes);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user