Improve snackbar and fix sentry (#7181)
- Improve snackbar to enable displaying multi-line message (so far we only displayed the first few words which was very frustrating) - Followup on previous issue to enable tim@apple.dev on the demo workspace (prefilled automatically) - Fix sentry tracing which had been broken when migrating from v7 to v8
This commit is contained in:
@ -12,6 +12,7 @@ import { existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs';
|
||||
import { SentryModule } from '@sentry/nestjs/setup';
|
||||
|
||||
import { CoreGraphQLApiModule } from 'src/engine/api/graphql/core-graphql-api.module';
|
||||
import { GraphQLConfigModule } from 'src/engine/api/graphql/graphql-config/graphql-config.module';
|
||||
@ -26,8 +27,10 @@ import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/
|
||||
import { ModulesModule } from 'src/modules/modules.module';
|
||||
|
||||
import { CoreEngineModule } from './engine/core-modules/core-engine.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
SentryModule.forRoot(),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
envFilePath: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
|
||||
|
||||
@ -6,15 +6,17 @@ export function SentryCronMonitor(monitorSlug: string, schedule: string) {
|
||||
propertyKey: string,
|
||||
descriptor: PropertyDescriptor,
|
||||
) {
|
||||
if (!Sentry.isInitialized()) {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
if (!Sentry.isInitialized()) {
|
||||
return await originalMethod.apply(this, args);
|
||||
}
|
||||
|
||||
let checkInId: string | undefined;
|
||||
|
||||
try {
|
||||
Sentry.captureCheckIn(
|
||||
checkInId = Sentry.captureCheckIn(
|
||||
{
|
||||
monitorSlug,
|
||||
status: 'in_progress',
|
||||
@ -25,13 +27,14 @@ export function SentryCronMonitor(monitorSlug: string, schedule: string) {
|
||||
value: schedule,
|
||||
},
|
||||
checkinMargin: 1,
|
||||
maxRuntime: 1,
|
||||
maxRuntime: 5,
|
||||
timezone: 'UTC',
|
||||
},
|
||||
);
|
||||
const result = await originalMethod.apply(this, args);
|
||||
|
||||
Sentry.captureCheckIn({
|
||||
checkInId,
|
||||
monitorSlug,
|
||||
status: 'ok',
|
||||
});
|
||||
@ -39,6 +42,7 @@ export function SentryCronMonitor(monitorSlug: string, schedule: string) {
|
||||
return result;
|
||||
} catch (error) {
|
||||
Sentry.captureCheckIn({
|
||||
checkInId,
|
||||
monitorSlug,
|
||||
status: 'error',
|
||||
});
|
||||
|
||||
@ -1,42 +1,13 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
||||
|
||||
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';
|
||||
import { ExceptionHandlerDriverInterface } from 'src/engine/core-modules/exception-handler/interfaces';
|
||||
|
||||
export class ExceptionHandlerSentryDriver
|
||||
implements ExceptionHandlerDriverInterface
|
||||
{
|
||||
constructor(options: ExceptionHandlerSentryDriverFactoryOptions['options']) {
|
||||
Sentry.init({
|
||||
environment: options.environment,
|
||||
release: options.release,
|
||||
dsn: options.dsn,
|
||||
integrations: [
|
||||
// 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,
|
||||
debug: options.debug,
|
||||
});
|
||||
}
|
||||
|
||||
captureExceptions(
|
||||
exceptions: ReadonlyArray<any>,
|
||||
options?: ExceptionHandlerOptions,
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import { DynamicModule, Global, Module } from '@nestjs/common';
|
||||
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { ExceptionHandlerDriver } from 'src/engine/core-modules/exception-handler/interfaces';
|
||||
import { EXCEPTION_HANDLER_DRIVER } from 'src/engine/core-modules/exception-handler/exception-handler.constants';
|
||||
import {
|
||||
ConfigurableModuleClass,
|
||||
OPTIONS_TYPE,
|
||||
ASYNC_OPTIONS_TYPE,
|
||||
} from 'src/engine/core-modules/exception-handler/exception-handler.module-definition';
|
||||
import { ExceptionHandlerConsoleDriver } from 'src/engine/core-modules/exception-handler/drivers/console.driver';
|
||||
import { ExceptionHandlerSentryDriver } from 'src/engine/core-modules/exception-handler/drivers/sentry.driver';
|
||||
import { EXCEPTION_HANDLER_DRIVER } from 'src/engine/core-modules/exception-handler/exception-handler.constants';
|
||||
import {
|
||||
ASYNC_OPTIONS_TYPE,
|
||||
ConfigurableModuleClass,
|
||||
OPTIONS_TYPE,
|
||||
} from 'src/engine/core-modules/exception-handler/exception-handler.module-definition';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { ExceptionHandlerDriver } from 'src/engine/core-modules/exception-handler/interfaces';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@ -23,7 +23,7 @@ export class ExceptionHandlerModule extends ConfigurableModuleClass {
|
||||
useValue:
|
||||
options.type === ExceptionHandlerDriver.Console
|
||||
? new ExceptionHandlerConsoleDriver()
|
||||
: new ExceptionHandlerSentryDriver(options.options),
|
||||
: new ExceptionHandlerSentryDriver(),
|
||||
};
|
||||
const dynamicModule = super.forRoot(options);
|
||||
|
||||
@ -45,7 +45,7 @@ export class ExceptionHandlerModule extends ConfigurableModuleClass {
|
||||
|
||||
return config.type === ExceptionHandlerDriver.Console
|
||||
? new ExceptionHandlerConsoleDriver()
|
||||
: new ExceptionHandlerSentryDriver(config.options);
|
||||
: new ExceptionHandlerSentryDriver();
|
||||
},
|
||||
inject: options.inject || [],
|
||||
};
|
||||
|
||||
@ -31,6 +31,7 @@ export const workspaceMemberPrefillData = async (
|
||||
nameLastName: 'A',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userEmail: 'noah@demo.dev',
|
||||
userId: DEMO_SEED_USER_IDS.NOAH,
|
||||
},
|
||||
{
|
||||
@ -39,6 +40,7 @@ export const workspaceMemberPrefillData = async (
|
||||
nameLastName: 'I',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userEmail: 'hugo@demo.dev',
|
||||
userId: DEMO_SEED_USER_IDS.HUGO,
|
||||
},
|
||||
{
|
||||
@ -47,6 +49,7 @@ export const workspaceMemberPrefillData = async (
|
||||
nameLastName: 'Apple',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userEmail: 'tim@apple.dev',
|
||||
userId: DEMO_SEED_USER_IDS.TIM,
|
||||
},
|
||||
])
|
||||
|
||||
29
packages/twenty-server/src/instrument.ts
Normal file
29
packages/twenty-server/src/instrument.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as Sentry from '@sentry/nestjs';
|
||||
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
||||
|
||||
import { ExceptionHandlerDriver } from 'src/engine/core-modules/exception-handler/interfaces';
|
||||
import { WorkspaceCacheKeys } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
|
||||
if (process.env.EXCEPTION_HANDLER_DRIVER === ExceptionHandlerDriver.Sentry) {
|
||||
Sentry.init({
|
||||
environment: process.env.SENTRY_ENVIRONMENT,
|
||||
release: process.env.SENTRY_RELEASE,
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
integrations: [
|
||||
// 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,
|
||||
debug: process.env.DEBUG_MODE === 'true',
|
||||
});
|
||||
}
|
||||
@ -2,7 +2,6 @@ import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
|
||||
import * as Sentry from '@sentry/node';
|
||||
import bytes from 'bytes';
|
||||
import { useContainer } from 'class-validator';
|
||||
import { graphqlUploadExpress } from 'graphql-upload';
|
||||
@ -11,6 +10,7 @@ import { LoggerService } from 'src/engine/core-modules/logger/logger.service';
|
||||
import { ApplyCorsToExceptions } from 'src/utils/apply-cors-to-exceptions';
|
||||
|
||||
import { AppModule } from './app.module';
|
||||
import './instrument';
|
||||
|
||||
import { settings } from './engine/constants/settings';
|
||||
import { generateFrontConfig } from './utils/generate-front-config';
|
||||
@ -34,10 +34,6 @@ const bootstrap = async () => {
|
||||
// Use our logger
|
||||
app.useLogger(logger);
|
||||
|
||||
if (Sentry.isInitialized()) {
|
||||
Sentry.setupExpressErrorHandler(app);
|
||||
}
|
||||
|
||||
app.useGlobalFilters(new ApplyCorsToExceptions());
|
||||
|
||||
// Apply validation pipes globally
|
||||
|
||||
@ -4,6 +4,7 @@ import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handl
|
||||
import { LoggerService } from 'src/engine/core-modules/logger/logger.service';
|
||||
import { shouldFilterException } from 'src/engine/utils/global-exception-handler.util';
|
||||
import { QueueWorkerModule } from 'src/queue-worker/queue-worker.module';
|
||||
import 'src/instrument';
|
||||
|
||||
async function bootstrap() {
|
||||
let exceptionHandlerService: ExceptionHandlerService | undefined;
|
||||
|
||||
Reference in New Issue
Block a user