Add response time to pubsub events (#646)
This commit is contained in:
parent
0a68b48acc
commit
aff725f570
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user