mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
feat: decouple error impact metrics from logger (#10311)
This commit is contained in:
parent
e516bbf14c
commit
3bb7426392
@ -8,21 +8,27 @@ import {
|
|||||||
|
|
||||||
const requestLogger: (config: IUnleashConfig) => RequestHandler = (config) => {
|
const requestLogger: (config: IUnleashConfig) => RequestHandler = (config) => {
|
||||||
const logger = config.getLogger('HTTP');
|
const logger = config.getLogger('HTTP');
|
||||||
const enable = config.server.enableRequestLogger;
|
const requestLoggerEnabled = config.server.enableRequestLogger;
|
||||||
const impactMetrics = config.flagResolver.impactMetrics;
|
const impactMetrics = config.flagResolver.impactMetrics;
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
if (enable) {
|
const impactMetricsEnabled =
|
||||||
res.on('finish', () => {
|
config.flagResolver.isEnabled('impactMetrics');
|
||||||
const { pathname } = url.parse(req.originalUrl);
|
|
||||||
|
res.on('finish', () => {
|
||||||
|
if (impactMetricsEnabled && impactMetrics) {
|
||||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||||
impactMetrics?.incrementCounter(CLIENT_ERROR_COUNT);
|
impactMetrics.incrementCounter(CLIENT_ERROR_COUNT);
|
||||||
}
|
}
|
||||||
if (res.statusCode >= 500) {
|
if (res.statusCode >= 500) {
|
||||||
impactMetrics?.incrementCounter(SERVER_ERROR_COUNT);
|
impactMetrics.incrementCounter(SERVER_ERROR_COUNT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestLoggerEnabled) {
|
||||||
|
const { pathname } = url.parse(req.originalUrl);
|
||||||
logger.info(`${res.statusCode} ${req.method} ${pathname}`);
|
logger.info(`${res.statusCode} ${req.method} ${pathname}`);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user