Improve sentry filtering and grouping (#12071)
Follow-up on https://github.com/twentyhq/twenty/pull/12007 In this PR - adding a filter on HttpExceptionHandlerService to filter out 4xx errors from driver handling (as we do for graphQL errors: see useGraphQLErrorHandler hook - only filteredIssues are sent to` exceptionHandlerService.captureExceptions()`.) - grouping together more missing metadata issues - attempting to use error codes as issues names in sentry to improve UI; for now it says "Error" all the time
This commit is contained in:
@ -18,6 +18,7 @@ export class ExceptionHandlerSentryDriver
|
||||
Sentry.withScope((scope) => {
|
||||
if (options?.operation) {
|
||||
scope.setExtra('operation', options.operation.name);
|
||||
scope.setExtra('operationType', options.operation.type);
|
||||
}
|
||||
|
||||
if (options?.document) {
|
||||
@ -57,6 +58,13 @@ export class ExceptionHandlerSentryDriver
|
||||
if (exception instanceof CustomException) {
|
||||
scope.setTag('customExceptionCode', exception.code);
|
||||
scope.setFingerprint([exception.code]);
|
||||
exception.name = exception.code
|
||||
.split('_')
|
||||
.map(
|
||||
(word) =>
|
||||
word.charAt(0)?.toUpperCase() + word.slice(1)?.toLowerCase(),
|
||||
)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
const eventId = Sentry.captureException(exception, {
|
||||
|
||||
@ -7,19 +7,9 @@ import { ExceptionHandlerUser } from 'src/engine/core-modules/exception-handler/
|
||||
import { ExceptionHandlerWorkspace } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-workspace.interface';
|
||||
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { handleException } from 'src/engine/utils/global-exception-handler.util';
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export const handleException = (
|
||||
exception: CustomException,
|
||||
exceptionHandlerService: ExceptionHandlerService,
|
||||
user?: ExceptionHandlerUser,
|
||||
workspace?: ExceptionHandlerWorkspace,
|
||||
): CustomException => {
|
||||
exceptionHandlerService.captureExceptions([exception], { user, workspace });
|
||||
|
||||
return exception;
|
||||
};
|
||||
|
||||
interface RequestAndParams {
|
||||
request: Request | null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@ -51,9 +41,16 @@ export class HttpExceptionHandlerService {
|
||||
workspace = { ...workspace, id: params.workspaceId };
|
||||
if (params?.userId) user = { ...user, id: params.userId };
|
||||
|
||||
handleException(exception, this.exceptionHandlerService, user, workspace);
|
||||
const statusCode = errorCode || 500;
|
||||
|
||||
handleException({
|
||||
exception,
|
||||
exceptionHandlerService: this.exceptionHandlerService,
|
||||
user,
|
||||
workspace,
|
||||
statusCode,
|
||||
});
|
||||
|
||||
return response.status(statusCode).send({
|
||||
statusCode,
|
||||
error: exception.name || 'Bad Request',
|
||||
|
||||
Reference in New Issue
Block a user