Add response time to pubsub events (#646)

This commit is contained in:
Esther Lozano 2020-03-10 11:27:17 +01:00 committed by GitHub
parent 0a68b48acc
commit aff725f570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,12 @@ function getEventData (req, res) {
attributes.event_group_id = eventGroupId;
}
const responseTime = getResponseTime(res);
if (responseTime) {
attributes.response_time = responseTime.toString();
}
return { event, attributes };
}
@ -52,4 +58,17 @@ function normalizedField (field) {
return field.toString().trim().substr(0, MAX_LENGTH);
}
function getResponseTime (res) {
const profiler = res.get('X-SQLAPI-Profiler');
let stats;
try {
stats = JSON.parse(profiler);
} catch (e) {
return undefined;
}
return stats.total;
}
module.exports = pubSubMetrics;