4d01e13a84
* Revert "Revert structured logging 2 (#1240)"
This reverts commit 78ecaeffcb.
* Logging should not be bundled into core shared directory
* making sure observability stuff isnt bundled into frontend
Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
26 lines
713 B
JavaScript
26 lines
713 B
JavaScript
/* istanbul ignore file */
|
|
const { logger } = require('@/logging/logging')
|
|
const prometheusClient = require('prom-client')
|
|
|
|
let metricErrorCount = null
|
|
|
|
module.exports = {
|
|
errorLoggingMiddleware(err, req, res, next) {
|
|
if (metricErrorCount === null) {
|
|
metricErrorCount = new prometheusClient.Counter({
|
|
name: 'speckle_server_request_errors',
|
|
help: 'Number of requests that threw exceptions',
|
|
labelNames: ['route']
|
|
})
|
|
}
|
|
|
|
logger.error(
|
|
`Error when handling ${req.originalUrl} from ${req.ip}: ${err.message}`
|
|
)
|
|
let route = 'unknown'
|
|
if (req.route && req.route.path) route = req.route.path
|
|
metricErrorCount.labels(route).inc()
|
|
next(err)
|
|
}
|
|
}
|