Skip to content

Commit c0552cf

Browse files
committed
Use .env variable to enable metrics
1 parent ede1bbe commit c0552cf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/middlewares/metrics/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const yaml = require('yamljs');
33
const client = require('prom-client');
44
const geoip = require('geoip-lite');
55
const rawSpec = yaml.load(`${__dirname}/../../docs/description.yml`);
6-
const { getHost, getConfig } = require('../../utils/auxiliar-functions');
6+
const { getHost } = require('../../utils/auxiliar-functions');
77

88

99
// ---------------------------------------------------------------------------
@@ -321,9 +321,8 @@ function anonymizeIp(ip) {
321321
return 'Unknown';
322322
}
323323

324-
function isMetricsEnabled(request) {
325-
const config = getConfig(request);
326-
return Boolean(config && config.metrics === true);
324+
function isMetricsEnabled() {
325+
return process.env.NODE_ENV === 'development';
327326
}
328327

329328
// ---------------------------------------------------------------------------
@@ -339,7 +338,7 @@ function metricsMiddleware(basePaths = ['/rest/current', '/rest/v1'], debug = fa
339338
const matchers = buildMatchers(basePaths);
340339

341340
return function trackMetrics(req, res, next) {
342-
if (!isMetricsEnabled(req)) {
341+
if (!isMetricsEnabled()) {
343342
return next();
344343
}
345344

@@ -399,7 +398,7 @@ function metricsMiddleware(basePaths = ['/rest/current', '/rest/v1'], debug = fa
399398
// Express route handler that serves the Prometheus text exposition format.
400399
// Supports PM2 cluster mode by aggregating metrics from all instances.
401400
async function metricsEndpoint(req, res) {
402-
if (!isMetricsEnabled(req)) {
401+
if (!isMetricsEnabled()) {
403402
return res.status(404).json({ error: 'Not Found' });
404403
}
405404

0 commit comments

Comments
 (0)