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");