From d21ab1aa4ee0525bba46478dde21672a71754422 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Tue, 2 Jan 2024 08:35:00 +0100 Subject: [PATCH] Lazyloaded `@sentry/profiling-node` dependency - we don't need to load this if we haven't configured Node profiling to occur - this might help fix random segfaults we've been seeing in CI, which only started occurring after this dependency was added --- ghost/core/core/shared/sentry.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ghost/core/core/shared/sentry.js b/ghost/core/core/shared/sentry.js index f267234453..a2966f4950 100644 --- a/ghost/core/core/shared/sentry.js +++ b/ghost/core/core/shared/sentry.js @@ -4,15 +4,6 @@ const SentryKnexTracingIntegration = require('./SentryKnexTracingIntegration'); const sentryConfig = config.get('sentry'); const errors = require('@tryghost/errors'); -// Import Sentry's profiling integration if available -let ProfilingIntegration; -try { - ({ProfilingIntegration} = require('@sentry/profiling-node')); -} catch (err) { - logging.warn('Sentry Profiling Integration not available'); - ProfilingIntegration = null; -} - const beforeSend = function (event, hint) { try { const exception = hint.originalException; @@ -85,9 +76,20 @@ if (sentryConfig && !sentryConfig.disabled) { sentryInitConfig.integrations.push(new Sentry.Integrations.Express()); sentryInitConfig.tracesSampleRate = parseFloat(sentryConfig.tracing.sampleRate) || 0.0; // Enable profiling, if configured, only if tracing is also configured - if (ProfilingIntegration && sentryConfig.profiling?.enabled === true) { - sentryInitConfig.integrations.push(new ProfilingIntegration()); - sentryInitConfig.profilesSampleRate = parseFloat(sentryConfig.profiling.sampleRate) || 0.0; + if (sentryConfig.profiling?.enabled === true) { + // Import Sentry's profiling integration if available + let ProfilingIntegration; + try { + ({ProfilingIntegration} = require('@sentry/profiling-node')); + } catch (err) { + logging.warn('Sentry Profiling Integration not available'); + ProfilingIntegration = null; + } + + if (ProfilingIntegration) { + sentryInitConfig.integrations.push(new ProfilingIntegration()); + sentryInitConfig.profilesSampleRate = parseFloat(sentryConfig.profiling.sampleRate) || 0.0; + } } } Sentry.init(sentryInitConfig);