Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit b1ff2c3

Browse files
committed
Remove path cardinality from metrics middleware
1 parent af3b817 commit b1ff2c3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

api/metrics/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function (){
22
'use strict';
3-
3+
const apiRoutes = ['cart', 'catalogue', 'orders', 'user'];
44
var express = require("express")
55
, client = require('prom-client')
66
, app = express()
@@ -31,7 +31,12 @@
3131
var start = process.hrtime();
3232

3333
response.on('finish', function() {
34-
observe(request.method, request.path, response.statusCode, start);
34+
// Only log API routes, and only record the backend service name (no unique identifiers)
35+
var model = request.path.split('/')[1];
36+
if (apiRoutes.indexOf(model) !== -1) {
37+
observe(request.method, model, response.statusCode, start);
38+
}
39+
3540
});
3641

3742
return done();

0 commit comments

Comments
 (0)