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;
|
||||
};
|
||||
}
|
||||
@ -1,13 +1,14 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { ProfilingIntegration } from '@sentry/profiling-node';
|
||||
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
||||
|
||||
import { ExceptionHandlerUser } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-user.interface';
|
||||
import { ExceptionHandlerOptions } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-options.interface';
|
||||
import { ExceptionHandlerUser } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-user.interface';
|
||||
|
||||
import {
|
||||
ExceptionHandlerDriverInterface,
|
||||
ExceptionHandlerSentryDriverFactoryOptions,
|
||||
} from 'src/engine/core-modules/exception-handler/interfaces';
|
||||
import { WorkspaceCacheKeys } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
|
||||
export class ExceptionHandlerSentryDriver
|
||||
implements ExceptionHandlerDriverInterface
|
||||
@ -18,11 +19,17 @@ export class ExceptionHandlerSentryDriver
|
||||
release: options.release,
|
||||
dsn: options.dsn,
|
||||
integrations: [
|
||||
new Sentry.Integrations.Http({ tracing: true }),
|
||||
new Sentry.Integrations.Express({ app: options.serverInstance }),
|
||||
new Sentry.Integrations.GraphQL(),
|
||||
new Sentry.Integrations.Postgres(),
|
||||
new ProfilingIntegration(),
|
||||
// TODO: Redis integration doesn't seem to work - investigate why
|
||||
Sentry.redisIntegration({
|
||||
cachePrefixes: Object.values(WorkspaceCacheKeys).map(
|
||||
(key) => `engine:${key}:`,
|
||||
),
|
||||
}),
|
||||
Sentry.httpIntegration(),
|
||||
Sentry.expressIntegration(),
|
||||
Sentry.graphqlIntegration(),
|
||||
Sentry.postgresIntegration(),
|
||||
nodeProfilingIntegration(),
|
||||
],
|
||||
tracesSampleRate: 0.1,
|
||||
profilesSampleRate: 0.3,
|
||||
|
||||
@ -13,8 +13,6 @@ export class CacheManager<T> {
|
||||
const [workspaceId] = cacheKey.split('-');
|
||||
|
||||
if (this.cache.has(cacheKey)) {
|
||||
console.log('Cache hit for key:', cacheKey);
|
||||
|
||||
return this.cache.get(cacheKey)!;
|
||||
}
|
||||
|
||||
@ -25,7 +23,6 @@ export class CacheManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Cache miss for key:', cacheKey);
|
||||
const value = await factory();
|
||||
|
||||
if (!value) {
|
||||
|
||||
@ -7,7 +7,7 @@ import { CacheStorageService } from 'src/engine/core-modules/cache-storage/servi
|
||||
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { ObjectMetadataMap } from 'src/engine/metadata-modules/utils/generate-object-metadata-map.util';
|
||||
|
||||
enum WorkspaceCacheKeys {
|
||||
export enum WorkspaceCacheKeys {
|
||||
GraphQLTypeDefs = 'graphql:type-defs',
|
||||
GraphQLUsedScalarNames = 'graphql:used-scalar-names',
|
||||
GraphQLOperations = 'graphql:operations',
|
||||
|
||||
Reference in New Issue
Block a user