jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
310 stars 68 forks source link

Add another example for normalizePath #102

Closed Cellaryllis closed 10 months ago

Cellaryllis commented 2 years ago

I added a new example for normalizePath as I struggled to get example 2 to work with our routes. Using the routes that are defined in code resulted in the cleanest result for our metrics, especially for our routes that have non-standard id formats in their paths.

Hopefully this example could help save some time for some other users of the package! :)

ineentho commented 1 year ago

While this is a cool solution, unfortunately it breaks when using routers:

const app = express();

app.get('/route', (req, res) => {
  console.log('root route', req.route?.path);
  res.send('');
});

const subRotuer = express.Router()

subRotuer.get('/route2', (req, res) => {
  console.log('route in router', req.route?.path);
  res.send('');
});

app.use('/router', subRotuer)

GET /route GET /router/route2

will log

root route /route
route in router /route2

Unfortunately, I haven't been able to solve this problem