Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add appname to http response time metrics
Browse files Browse the repository at this point in the history
ivarconr committed Sep 30, 2022
1 parent 9ba441b commit 1577df8
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib/metrics.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ export default class MetricsMonitor {
const requestDuration = new client.Summary({
name: 'http_request_duration_milliseconds',
help: 'App response time',
labelNames: ['path', 'method', 'status'],
labelNames: ['path', 'method', 'status', 'appName'],
percentiles: [0.1, 0.5, 0.9, 0.95, 0.99],
maxAgeSeconds: 600,
ageBuckets: 5,
@@ -143,8 +143,10 @@ export default class MetricsMonitor {

eventBus.on(
events.REQUEST_TIME,
({ path, method, time, statusCode }) => {
requestDuration.labels(path, method, statusCode).observe(time);
({ path, method, time, statusCode, appName }) => {
requestDuration
.labels(path, method, statusCode, appName)
.observe(time);
},
);

3 changes: 3 additions & 0 deletions src/lib/middleware/response-time-metrics.ts
Original file line number Diff line number Diff line change
@@ -11,11 +11,14 @@ export function responseTimeMetrics(eventBus: EventEmitter): any {

const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)';

const appName = req.headers['unleash-appname'];

const timingInfo = {
path: pathname,
method: req.method,
statusCode,
time,
appName,
};
eventBus.emit(REQUEST_TIME, timingInfo);
});

0 comments on commit 1577df8

Please sign in to comment.