From ff22988caf5bf7264218e7181e3f2626b4faf1f0 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 4 May 2026 11:09:48 +0200 Subject: [PATCH] revert: Sentry #20064 + @sentry 10.27 (prod bisect) (#20221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Reverts **#20064** (`feat(sentry): propagate workspace context to all spans`) and downgrades **@sentry** packages from **10.51** back to **10.27** (reversing **#20149**), to validate in production whether recent Sentry/instrumentation changes correlate with OTLP/metrics issues. ## Changes 1. **Revert #20064** — removes `beforeSendSpan` from `instrument.ts`, restores `WorkspaceAuthContextMiddleware` / `BullMQDriver` behavior, and deletes the three `apply-workspace-sentry-*` utils added in that PR. 2. **Sentry versions** — `packages/twenty-server` (`@sentry/nestjs`, `@sentry/node`, `@sentry/profiling-node`) and `packages/twenty-front` (`@sentry/react`) set to `^10.27.0`; `yarn.lock` regenerated via `yarn install`. --------- Co-authored-by: Cursor --- packages/twenty-front/package.json | 2 +- packages/twenty-server/package.json | 6 +-- .../workspace-auth-context.middleware.ts | 3 -- .../message-queue/drivers/bullmq.driver.ts | 39 ++++++++----------- ...space-sentry-context-from-job-data.util.ts | 25 ------------ .../apply-workspace-sentry-context.util.ts | 27 ------------- .../apply-workspace-sentry-fields.util.ts | 26 ------------- packages/twenty-server/src/instrument.ts | 23 ----------- yarn.lock | 16 ++++---- 9 files changed, 29 insertions(+), 138 deletions(-) delete mode 100644 packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context-from-job-data.util.ts delete mode 100644 packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context.util.ts delete mode 100644 packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util.ts diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json index 0cc2b67ed1..00ad214758 100644 --- a/packages/twenty-front/package.json +++ b/packages/twenty-front/package.json @@ -57,7 +57,7 @@ "@react-email/components": "^0.5.3", "@react-pdf/renderer": "^4.1.6", "@scalar/api-reference-react": "^0.4.36", - "@sentry/react": "^10.51.0", + "@sentry/react": "^10.27.0", "@sniptt/guards": "^0.2.0", "@tiptap/core": "3.4.2", "@tiptap/extension-bold": "3.4.2", diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 68bcf9620b..a5ed9ba6ac 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -78,9 +78,9 @@ "@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch", "@ptc-org/nestjs-query-typeorm": "4.2.1-alpha.2", "@react-email/render": "^1.2.3", - "@sentry/nestjs": "^10.51.0", - "@sentry/node": "^10.51.0", - "@sentry/profiling-node": "^10.51.0", + "@sentry/nestjs": "^10.27.0", + "@sentry/node": "^10.27.0", + "@sentry/profiling-node": "^10.27.0", "@sniptt/guards": "0.2.0", "addressparser": "1.0.1", "ai": "6.0.97", diff --git a/packages/twenty-server/src/engine/core-modules/auth/middlewares/workspace-auth-context.middleware.ts b/packages/twenty-server/src/engine/core-modules/auth/middlewares/workspace-auth-context.middleware.ts index 23c87cd7d8..c446be9c32 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/middlewares/workspace-auth-context.middleware.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/middlewares/workspace-auth-context.middleware.ts @@ -13,7 +13,6 @@ import { buildApiKeyAuthContext } from 'src/engine/core-modules/auth/utils/build import { buildApplicationAuthContext } from 'src/engine/core-modules/auth/utils/build-application-auth-context.util'; import { buildPendingActivationUserAuthContext } from 'src/engine/core-modules/auth/utils/build-pending-activation-user-auth-context.util'; import { buildUserAuthContext } from 'src/engine/core-modules/auth/utils/build-user-auth-context.util'; -import { applyWorkspaceSentryContext } from 'src/engine/core-modules/sentry/utils/apply-workspace-sentry-context.util'; @Injectable() export class WorkspaceAuthContextMiddleware implements NestMiddleware { @@ -26,8 +25,6 @@ export class WorkspaceAuthContextMiddleware implements NestMiddleware { const authContext = this.buildAuthContext(req); - applyWorkspaceSentryContext(authContext); - withWorkspaceAuthContext(authContext, () => { next(); }); diff --git a/packages/twenty-server/src/engine/core-modules/message-queue/drivers/bullmq.driver.ts b/packages/twenty-server/src/engine/core-modules/message-queue/drivers/bullmq.driver.ts index dedb66ac09..0f94e52594 100644 --- a/packages/twenty-server/src/engine/core-modules/message-queue/drivers/bullmq.driver.ts +++ b/packages/twenty-server/src/engine/core-modules/message-queue/drivers/bullmq.driver.ts @@ -4,7 +4,6 @@ import { type OnModuleInit, } from '@nestjs/common'; -import * as Sentry from '@sentry/node'; import { type JobsOptions, MetricsTime, @@ -29,7 +28,6 @@ import { type MessageQueue } from 'src/engine/core-modules/message-queue/message import { getJobKey } from 'src/engine/core-modules/message-queue/utils/get-job-key.util'; import { type MetricsService } from 'src/engine/core-modules/metrics/metrics.service'; import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type'; -import { applyWorkspaceSentryContextFromJobData } from 'src/engine/core-modules/sentry/utils/apply-workspace-sentry-context-from-job-data.util'; export type BullMQDriverOptions = QueueOptions; @@ -110,28 +108,25 @@ export class BullMQDriver this.workerMap[queueName] = new Worker( queueName, - async (job) => - Sentry.withIsolationScope(async () => { - applyWorkspaceSentryContextFromJobData(job.data); + async (job) => { + // TODO: Correctly support for job.id + const timeStart = performance.now(); + const workspaceId = job.data?.workspaceId; + const workspaceSuffix = workspaceId + ? ` [workspace=${workspaceId}]` + : ''; - // TODO: Correctly support for job.id - const timeStart = performance.now(); - const workspaceId = job.data?.workspaceId; - const workspaceSuffix = workspaceId - ? ` [workspace=${workspaceId}]` - : ''; + this.logger.log( + `Processing job ${job.id} with name ${job.name} on queue ${queueName}${workspaceSuffix}`, + ); + await handler({ data: job.data, id: job.id ?? '', name: job.name }); + const timeEnd = performance.now(); + const executionTime = timeEnd - timeStart; - this.logger.log( - `Processing job ${job.id} with name ${job.name} on queue ${queueName}${workspaceSuffix}`, - ); - await handler({ data: job.data, id: job.id ?? '', name: job.name }); - const timeEnd = performance.now(); - const executionTime = timeEnd - timeStart; - - this.logger.log( - `Job ${job.id} with name ${job.name} processed on queue ${queueName} in ${executionTime.toFixed(2)}ms${workspaceSuffix}`, - ); - }), + this.logger.log( + `Job ${job.id} with name ${job.name} processed on queue ${queueName} in ${executionTime.toFixed(2)}ms${workspaceSuffix}`, + ); + }, workerOptions, ); diff --git a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context-from-job-data.util.ts b/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context-from-job-data.util.ts deleted file mode 100644 index 0d78ba3515..0000000000 --- a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context-from-job-data.util.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { applyWorkspaceSentryFields } from 'src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util'; - -export const applyWorkspaceSentryContextFromJobData = ( - jobData: unknown, -): void => { - if (typeof jobData !== 'object' || jobData === null) { - return; - } - - const workspaceId = (jobData as { workspaceId?: unknown }).workspaceId; - const userWorkspaceId = (jobData as { userWorkspaceId?: unknown }) - .userWorkspaceId; - - if (typeof workspaceId !== 'string' || workspaceId.length === 0) { - return; - } - - applyWorkspaceSentryFields({ - workspaceId, - userWorkspaceId: - typeof userWorkspaceId === 'string' && userWorkspaceId.length > 0 - ? userWorkspaceId - : undefined, - }); -}; diff --git a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context.util.ts b/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context.util.ts deleted file mode 100644 index 3c9ea343d8..0000000000 --- a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-context.util.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { type WorkspaceAuthContext } from 'src/engine/core-modules/auth/types/workspace-auth-context.type'; -import { applyWorkspaceSentryFields } from 'src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util'; - -export const applyWorkspaceSentryContext = ( - authContext: WorkspaceAuthContext, -): void => { - const workspaceId = authContext.workspace?.id; - - if (!workspaceId) { - return; - } - - switch (authContext.type) { - case 'user': - case 'pendingActivationUser': - applyWorkspaceSentryFields({ - workspaceId, - userWorkspaceId: authContext.userWorkspaceId, - }); - return; - case 'apiKey': - case 'application': - case 'system': - applyWorkspaceSentryFields({ workspaceId }); - return; - } -}; diff --git a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util.ts b/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util.ts deleted file mode 100644 index a65e17d3d5..0000000000 --- a/packages/twenty-server/src/engine/core-modules/sentry/utils/apply-workspace-sentry-fields.util.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as Sentry from '@sentry/node'; - -type WorkspaceSentryFields = { - workspaceId: string; - userWorkspaceId?: string; -}; - -export const applyWorkspaceSentryFields = ( - fields: WorkspaceSentryFields, -): void => { - Sentry.setUser({ - id: fields.userWorkspaceId ?? fields.workspaceId, - }); - - Sentry.setTag('twenty.workspace.id', fields.workspaceId); - if (fields.userWorkspaceId) { - Sentry.setTag('twenty.user_workspace.id', fields.userWorkspaceId); - } - - Sentry.setContext('twenty', { - workspace_id: fields.workspaceId, - ...(fields.userWorkspaceId && { - user_workspace_id: fields.userWorkspaceId, - }), - }); -}; diff --git a/packages/twenty-server/src/instrument.ts b/packages/twenty-server/src/instrument.ts index 1c09ae04b0..217d123139 100644 --- a/packages/twenty-server/src/instrument.ts +++ b/packages/twenty-server/src/instrument.ts @@ -45,29 +45,6 @@ if (process.env.EXCEPTION_HANDLER_DRIVER === ExceptionHandlerDriver.SENTRY) { profilesSampleRate: 0.3, sendDefaultPii: true, debug: process.env.NODE_ENV === NodeEnvironment.DEVELOPMENT, - beforeSendSpan: (span) => { - const twentyContext = Sentry.getIsolationScope().getScopeData().contexts - ?.twenty as - | { - workspace_id?: string; - user_workspace_id?: string; - } - | undefined; - - if (!twentyContext?.workspace_id) { - return span; - } - - span.data = { - ...span.data, - 'twenty.workspace.id': twentyContext.workspace_id, - ...(twentyContext.user_workspace_id && { - 'twenty.user_workspace.id': twentyContext.user_workspace_id, - }), - }; - - return span; - }, }); } diff --git a/yarn.lock b/yarn.lock index 88ed01b1c7..d96a118835 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20408,7 +20408,7 @@ __metadata: languageName: node linkType: hard -"@sentry/nestjs@npm:^10.51.0": +"@sentry/nestjs@npm:^10.27.0": version: 10.51.0 resolution: "@sentry/nestjs@npm:10.51.0" dependencies: @@ -20457,7 +20457,7 @@ __metadata: languageName: node linkType: hard -"@sentry/node@npm:10.51.0, @sentry/node@npm:^10.51.0": +"@sentry/node@npm:10.51.0, @sentry/node@npm:^10.27.0": version: 10.51.0 resolution: "@sentry/node@npm:10.51.0" dependencies: @@ -20510,7 +20510,7 @@ __metadata: languageName: node linkType: hard -"@sentry/profiling-node@npm:^10.51.0": +"@sentry/profiling-node@npm:^10.27.0": version: 10.51.0 resolution: "@sentry/profiling-node@npm:10.51.0" dependencies: @@ -20523,7 +20523,7 @@ __metadata: languageName: node linkType: hard -"@sentry/react@npm:^10.51.0": +"@sentry/react@npm:^10.27.0": version: 10.51.0 resolution: "@sentry/react@npm:10.51.0" dependencies: @@ -57848,7 +57848,7 @@ __metadata: "@react-email/components": "npm:^0.5.3" "@react-pdf/renderer": "npm:^4.1.6" "@scalar/api-reference-react": "npm:^0.4.36" - "@sentry/react": "npm:^10.51.0" + "@sentry/react": "npm:^10.27.0" "@sniptt/guards": "npm:^0.2.0" "@storybook-community/storybook-addon-cookie": "npm:^5.0.0" "@storybook/addon-coverage": "npm:^3.0.0" @@ -58096,9 +58096,9 @@ __metadata: "@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch" "@ptc-org/nestjs-query-typeorm": "npm:4.2.1-alpha.2" "@react-email/render": "npm:^1.2.3" - "@sentry/nestjs": "npm:^10.51.0" - "@sentry/node": "npm:^10.51.0" - "@sentry/profiling-node": "npm:^10.51.0" + "@sentry/nestjs": "npm:^10.27.0" + "@sentry/node": "npm:^10.27.0" + "@sentry/profiling-node": "npm:^10.27.0" "@sniptt/guards": "npm:0.2.0" "@swc/cli": "npm:^0.7.10" "@swc/core": "npm:^1.15.11"