Choosing the Right Metric Type
Spot the bug in instrumenting HTTP latency, one of the three observability pillars.
Codejavascript
const client = require('prom-client');
// Track how long each HTTP request takes
const httpDuration = new client.Counter({
name: 'http_request_duration_seconds',
help: 'Duration of HTTP requests in seconds'
});
app.get('/api', (req, res) => {
const start = Date.now();
res.on('finish', () => {
const duration = (Date.now() - start) / 1000;
httpDuration.inc(duration);
});
res.send('ok');
});What is the bug in this metrics instrumentation code?