|
2 | 2 | require('@codefresh-io/cf-telemetry/init'); |
3 | 3 | // ↓ Keep one blank line below to prevent automatic import reordering |
4 | 4 |
|
| 5 | +const otel = require('@codefresh-io/cf-telemetry/otel'); |
5 | 6 | const path = require('node:path'); |
6 | 7 | const cflogs = require('cf-logs'); |
7 | 8 |
|
| 9 | +const unhandledErrorsTotal = otel.cf.getMeter().createCounter( |
| 10 | + 'codefresh.unhandled_errors', |
| 11 | + { |
| 12 | + description: 'Number of unhandled errors', |
| 13 | + unit: '{unhandled_error}', |
| 14 | + valueType: otel.api.ValueType.INT, |
| 15 | + }, |
| 16 | +); |
| 17 | + |
8 | 18 | const loggerOptions = { |
9 | 19 | filePath: path.join(__dirname, '../logs', 'logs.log'), |
10 | 20 | console: process.env.LOG_TO_CONSOLE || false, |
@@ -45,12 +55,14 @@ process.on('exit', (code) => { |
45 | 55 | }); |
46 | 56 |
|
47 | 57 | process.on('uncaughtException', (error) => { |
| 58 | + unhandledErrorsTotal.add(1, { 'cf.unhandled_error.type': 'uncaughtException' }); |
48 | 59 | console.log(`uncaughtException: ${error}`); |
49 | 60 | logger.state.uncaughtException = error; |
50 | 61 | logger._writeNewState(); |
51 | 62 | }); |
52 | 63 |
|
53 | 64 | process.on('unhandledRejection', (reason) => { |
| 65 | + unhandledErrorsTotal.add(1, { 'cf.unhandled_error.type': 'unhandledRejection' }); |
54 | 66 | console.log(`unhandledRejection: ${reason}`); |
55 | 67 | logger.state.unhandledRejection = reason; |
56 | 68 | logger._writeNewState(); |
|
0 commit comments