mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01: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 logger = config.getLogger('HTTP'); | ||||
|     const enable = config.server.enableRequestLogger; | ||||
|     const requestLoggerEnabled = config.server.enableRequestLogger; | ||||
|     const impactMetrics = config.flagResolver.impactMetrics; | ||||
|     return (req, res, next) => { | ||||
|         if (enable) { | ||||
|             res.on('finish', () => { | ||||
|                 const { pathname } = url.parse(req.originalUrl); | ||||
|         const impactMetricsEnabled = | ||||
|             config.flagResolver.isEnabled('impactMetrics'); | ||||
| 
 | ||||
|         res.on('finish', () => { | ||||
|             if (impactMetricsEnabled && impactMetrics) { | ||||
|                 if (res.statusCode >= 400 && res.statusCode < 500) { | ||||
|                     impactMetrics?.incrementCounter(CLIENT_ERROR_COUNT); | ||||
|                     impactMetrics.incrementCounter(CLIENT_ERROR_COUNT); | ||||
|                 } | ||||
|                 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}`); | ||||
|             }); | ||||
|         } | ||||
|             } | ||||
|         }); | ||||
|         next(); | ||||
|     }; | ||||
| }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user