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 Michael Barrett
parent b639993a1b
commit a667b160c1
No known key found for this signature in database

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;
@ -89,9 +80,20 @@ if (sentryConfig && !sentryConfig.disabled) {
sentryInitConfig.integrations.push(new Sentry.Integrations.Http({tracing: true}));
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);