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
This commit is contained in:
Daniel Lockyer 2024-01-02 08:35:00 +01:00 committed by Daniel Lockyer
parent 3508cd12fe
commit d21ab1aa4e

View File

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