Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
requestDurationGenerator,
} = require('./metrics');
const {
normalizeStatusCode,
normalizePath,
} = require('./normalizers');
const defaultOptions = {
metricsPath: '/metrics',
metricsApp: null,
authenticate: null,
collectDefaultMetrics: true,
// buckets for response time from 0.05s to 2.5s
// these are aribtrary values since i dont know any better ¯\_(ツ)_/¯
requestDurationBuckets: Prometheus.exponentialBuckets(0.05, 1.75, 8),
extraMasks: [],
};
module.exports = (userOptions = {}) => {
const options = { ...defaultOptions, ...userOptions };
const { metricsPath, metricsApp } = options;
// if no app is provided, instantiate one
const app = metricsApp || express();
app.disable('x-powered-by');
const requestDuration = requestDurationGenerator(options.requestDurationBuckets, options.prefix);
const requestCount = requestCountGenerator(options.prefix);
/**