From 70a533c3652df5e5e140c7a0c6858c38e2627c0b Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 24 Aug 2026 20:17:46 -0700 Subject: [PATCH 1/3] feat(web): make Sentry tracing and profiling opt-in --- .env.development | 2 ++ packages/web/src/sentry.edge.config.ts | 6 +++++- packages/web/src/sentry.server.config.ts | 22 ++++++++++++++-------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.env.development b/.env.development index 89b9b9e14..22b6863e7 100644 --- a/.env.development +++ b/.env.development @@ -30,6 +30,8 @@ CONFIG_PATH=${PWD}/config.json # Path to the sourcebot config file (if one exist # NEXT_PUBLIC_SENTRY_WEBAPP_DSN="" # SENTRY_ENVIRONMENT="dev" # NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev" +# SENTRY_TRACING_ENABLED="false" # Set to "true" to enable server and edge tracing. +# SENTRY_PROFILING_ENABLED="false" # Set to "true" to enable server-side profiling. Requires tracing. # SENTRY_AUTH_TOKEN= # Logtail diff --git a/packages/web/src/sentry.edge.config.ts b/packages/web/src/sentry.edge.config.ts index 05c897ac1..44f03a63d 100644 --- a/packages/web/src/sentry.edge.config.ts +++ b/packages/web/src/sentry.edge.config.ts @@ -5,12 +5,16 @@ import * as Sentry from "@sentry/nextjs"; +const isTracingEnabled = process.env.SENTRY_TRACING_ENABLED === 'true'; + if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) { Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN, environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, - tracesSampleRate: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === 'development' ? 1.0 : 0.1, + ...(isTracingEnabled ? { + tracesSampleRate: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === 'development' ? 1.0 : 0.1, + } : {}), // Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false, diff --git a/packages/web/src/sentry.server.config.ts b/packages/web/src/sentry.server.config.ts index 6ba395674..bb21c644d 100644 --- a/packages/web/src/sentry.server.config.ts +++ b/packages/web/src/sentry.server.config.ts @@ -7,19 +7,25 @@ import { nodeProfilingIntegration } from "@sentry/profiling-node"; import { createLogger } from "@sourcebot/shared"; const logger = createLogger('sentry-server-config'); +const isTracingEnabled = process.env.SENTRY_TRACING_ENABLED === 'true'; +const isProfilingEnabled = isTracingEnabled && process.env.SENTRY_PROFILING_ENABLED === 'true'; if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) { Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN, environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, - integrations: [ - nodeProfilingIntegration(), - ], - tracesSampleRate: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === 'development' ? 1.0 : 0.1, - // Evaluated once per `Sentry.init()`, i.e. once per server process. - profileSessionSampleRate: 1.0, - // Profile only while a sampled root span is active, rather than continuously. - profileLifecycle: 'trace', + ...(isTracingEnabled ? { + tracesSampleRate: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === 'development' ? 1.0 : 0.1, + } : {}), + ...(isProfilingEnabled ? { + integrations: [ + nodeProfilingIntegration(), + ], + // Evaluated once per `Sentry.init()`, i.e. once per server process. + profileSessionSampleRate: 1.0, + // Profile only while a sampled root span is active, rather than continuously. + profileLifecycle: 'trace' as const, + } : {}), }); } else { logger.debug("[server] Sentry was not initialized"); From 99d238115802ee76f586255cf5e7419495813e36 Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 24 Aug 2026 20:18:37 -0700 Subject: [PATCH 2/3] docs: add changelog entry for Sentry controls --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc87fa78a..62739a35e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Made Sentry tracing and profiling opt-in through environment variables. [#1616](https://github.com/sourcebot-dev/sourcebot/pull/1616) + ## [5.1.9] - 2026-08-22 ### Fixed From 3f6bd63d52781be09a6062f9553d5ba012271fdc Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 24 Aug 2026 20:21:55 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62739a35e..dc87fa78a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed -- Made Sentry tracing and profiling opt-in through environment variables. [#1616](https://github.com/sourcebot-dev/sourcebot/pull/1616) - ## [5.1.9] - 2026-08-22 ### Fixed