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:
Félix Malfait
2024-09-19 18:09:24 +02:00
committed by GitHub
parent b3ed6cb903
commit 3025ac346c
22 changed files with 879 additions and 210 deletions

View File

@ -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;
};
}