Skip to content

Commit 7833966

Browse files
committed
feat: add codefresh.unhandled_errors metric
1 parent ca7ca71 commit 7833966

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
require('@codefresh-io/cf-telemetry/init');
33
// ↓ Keep one blank line below to prevent automatic import reordering
44

5+
const otel = require('@codefresh-io/cf-telemetry/otel');
56
const path = require('node:path');
67
const cflogs = require('cf-logs');
78

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+
818
const loggerOptions = {
919
filePath: path.join(__dirname, '../logs', 'logs.log'),
1020
console: process.env.LOG_TO_CONSOLE || false,
@@ -45,12 +55,14 @@ process.on('exit', (code) => {
4555
});
4656

4757
process.on('uncaughtException', (error) => {
58+
unhandledErrorsTotal.add(1, { 'cf.unhandled_error.type': 'uncaughtException' });
4859
console.log(`uncaughtException: ${error}`);
4960
logger.state.uncaughtException = error;
5061
logger._writeNewState();
5162
});
5263

5364
process.on('unhandledRejection', (reason) => {
65+
unhandledErrorsTotal.add(1, { 'cf.unhandled_error.type': 'unhandledRejection' });
5466
console.log(`unhandledRejection: ${reason}`);
5567
logger.state.unhandledRejection = reason;
5668
logger._writeNewState();

0 commit comments

Comments
 (0)