Upgrade sentry (#7145)
Upgrave Sentry to v8 and add Sentry Cron monitoring --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
|
||||
export function SentryCronMonitor(monitorSlug: string, schedule: string) {
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string,
|
||||
descriptor: PropertyDescriptor,
|
||||
) {
|
||||
if (!Sentry.isInitialized()) {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
try {
|
||||
Sentry.captureCheckIn(
|
||||
{
|
||||
monitorSlug,
|
||||
status: 'in_progress',
|
||||
},
|
||||
{
|
||||
schedule: {
|
||||
type: 'crontab',
|
||||
value: schedule,
|
||||
},
|
||||
checkinMargin: 1,
|
||||
maxRuntime: 1,
|
||||
timezone: 'UTC',
|
||||
},
|
||||
);
|
||||
const result = await originalMethod.apply(this, args);
|
||||
|
||||
Sentry.captureCheckIn({
|
||||
monitorSlug,
|
||||
status: 'ok',
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
Sentry.captureCheckIn({
|
||||
monitorSlug,
|
||||
status: 'error',
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user