Skip to content

Commit

Permalink
feat(http): track response time by status code
Browse files Browse the repository at this point in the history
Track response time by status code (2xx, 3xx, 4xx, and 5xx).

New metrics that will be emitted:

- http.response_time.2xx
- http.response_time.3xx
- http.response_time.4xx
- http.response_time.5xx
  • Loading branch information
hassy committed Aug 23, 2024
1 parent cf68ee6 commit 7f28558
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/core/lib/engine_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,34 @@ HttpEngine.prototype._handleResponse = function (
ee.emit('counter', 'http.responses', 1);
// ee.emit('rate', 'http.response_rate');
ee.emit('histogram', 'http.response_time', res.timings.phases.firstByte);

const statusCode = res.statusCode;
if (statusCode >= 200 && statusCode < 300) {
ee.emit(
'histogram',
'http.response_time.2xx',
res.timings.phases.firstByte
);
} else if (statusCode >= 300 && statusCode < 400) {
ee.emit(
'histogram',
'http.response_time.3xx',
res.timings.phases.firstByte
);
} else if (statusCode >= 400 && statusCode < 500) {
ee.emit(
'histogram',
'http.response_time.4xx',
res.timings.phases.firstByte
);
} else if (statusCode >= 500 && statusCode < 600) {
ee.emit(
'histogram',
'http.response_time.5xx',
res.timings.phases.firstByte
);
}

if (this.extendedHTTPMetrics) {
ee.emit('histogram', 'http.dns', res.timings.phases.dns);
ee.emit('histogram', 'http.tcp', res.timings.phases.tcp);
Expand Down

0 comments on commit 7f28558

Please sign in to comment.