From 8f89b0f3c291d6cb3ad1d89d2ce6b9b06cd6942e Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 31 Jul 2025 11:23:31 +0200 Subject: [PATCH 1/2] ref(node-core): Add `mechanism` to cron instrumentations --- packages/node-core/src/cron/cron.ts | 20 ++++++++++++++++++-- packages/node-core/src/cron/node-cron.ts | 7 ++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/node-core/src/cron/cron.ts b/packages/node-core/src/cron/cron.ts index ce6225ced2fa..5c0b8a807ce5 100644 --- a/packages/node-core/src/cron/cron.ts +++ b/packages/node-core/src/cron/cron.ts @@ -99,7 +99,15 @@ export function instrumentCron(lib: T & CronJobConstructor, monitorSlug: stri try { await onTick(context, onComplete); } catch (e) { - captureException(e); + captureException(e, { + mechanism: { + handled: false, + type: 'cron.instrumentCron', + data: { + function: 'constructor', + }, + }, + }); throw e; } }, @@ -136,7 +144,15 @@ export function instrumentCron(lib: T & CronJobConstructor, monitorSlug: stri try { await onTick(context, onComplete); } catch (e) { - captureException(e); + captureException(e, { + mechanism: { + handled: false, + type: 'cron.instrumentCron.on-tick', + data: { + function: 'from', + }, + }, + }); throw e; } }, diff --git a/packages/node-core/src/cron/node-cron.ts b/packages/node-core/src/cron/node-cron.ts index 5b9e48900287..e03f2700bf9a 100644 --- a/packages/node-core/src/cron/node-cron.ts +++ b/packages/node-core/src/cron/node-cron.ts @@ -53,7 +53,12 @@ export function instrumentNodeCron(lib: Partial & T): T { try { return await callback(); } catch (e) { - captureException(e); + captureException(e, { + mechanism: { + handled: false, + type: 'cron.instrumentNodeCron', + }, + }); throw e; } }, From 0c60aa2de62dc80b3b93a1d93a111efb198196bd Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 5 Sep 2025 17:38:41 +0200 Subject: [PATCH 2/2] adjust tests --- .../suites/cron/cron/test.ts | 10 +++++++++- .../suites/cron/node-cron/test.ts | 10 +++++++++- .../suites/cron/node-schedule/test.ts | 10 +++++++++- packages/node-core/src/cron/cron.ts | 10 ++-------- packages/node-core/src/cron/node-cron.ts | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dev-packages/node-core-integration-tests/suites/cron/cron/test.ts b/dev-packages/node-core-integration-tests/suites/cron/cron/test.ts index 8b9fdfd5c593..c7d0ca5239fc 100644 --- a/dev-packages/node-core-integration-tests/suites/cron/cron/test.ts +++ b/dev-packages/node-core-integration-tests/suites/cron/cron/test.ts @@ -69,7 +69,15 @@ test('cron instrumentation', async () => { }) .expect({ event: { - exception: { values: [{ type: 'Error', value: 'Error in cron job' }] }, + exception: { + values: [ + { + type: 'Error', + value: 'Error in cron job', + mechanism: { type: 'auto.function.cron.instrumentCron', handled: false }, + }, + ], + }, }, }) .start() diff --git a/dev-packages/node-core-integration-tests/suites/cron/node-cron/test.ts b/dev-packages/node-core-integration-tests/suites/cron/node-cron/test.ts index 1c5fa515e208..fb3e7bacbf45 100644 --- a/dev-packages/node-core-integration-tests/suites/cron/node-cron/test.ts +++ b/dev-packages/node-core-integration-tests/suites/cron/node-cron/test.ts @@ -69,7 +69,15 @@ test('node-cron instrumentation', async () => { }) .expect({ event: { - exception: { values: [{ type: 'Error', value: 'Error in cron job' }] }, + exception: { + values: [ + { + type: 'Error', + value: 'Error in cron job', + mechanism: { type: 'auto.function.node-cron.instrumentNodeCron', handled: false }, + }, + ], + }, }, }) .start() diff --git a/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts b/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts index a2019253203f..19d2d0b4e339 100644 --- a/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts +++ b/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts @@ -69,7 +69,15 @@ test('node-schedule instrumentation', async () => { }) .expect({ event: { - exception: { values: [{ type: 'Error', value: 'Error in cron job' }] }, + exception: { + values: [ + { + type: 'Error', + value: 'Error in cron job', + mechanism: { type: 'onunhandledrejection', handled: false }, + }, + ], + }, }, }) .start() diff --git a/packages/node-core/src/cron/cron.ts b/packages/node-core/src/cron/cron.ts index 5c0b8a807ce5..2c764c877c46 100644 --- a/packages/node-core/src/cron/cron.ts +++ b/packages/node-core/src/cron/cron.ts @@ -102,10 +102,7 @@ export function instrumentCron(lib: T & CronJobConstructor, monitorSlug: stri captureException(e, { mechanism: { handled: false, - type: 'cron.instrumentCron', - data: { - function: 'constructor', - }, + type: 'auto.function.cron.instrumentCron', }, }); throw e; @@ -147,10 +144,7 @@ export function instrumentCron(lib: T & CronJobConstructor, monitorSlug: stri captureException(e, { mechanism: { handled: false, - type: 'cron.instrumentCron.on-tick', - data: { - function: 'from', - }, + type: 'auto.function.cron.instrumentCron', }, }); throw e; diff --git a/packages/node-core/src/cron/node-cron.ts b/packages/node-core/src/cron/node-cron.ts index e03f2700bf9a..a2374b06d4b5 100644 --- a/packages/node-core/src/cron/node-cron.ts +++ b/packages/node-core/src/cron/node-cron.ts @@ -56,7 +56,7 @@ export function instrumentNodeCron(lib: Partial & T): T { captureException(e, { mechanism: { handled: false, - type: 'cron.instrumentNodeCron', + type: 'auto.function.node-cron.instrumentNodeCron', }, }); throw e;