Add response time to pubsub events (#1155)
This commit is contained in:
parent
28c4e89ab5
commit
7b8cc0a8b8
@ -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-Tiler-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