0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added Sentry performance monitoring to Ghost Server (#19243)

refs ARCH-21

- We currently have NewRelic setup for a few of our largest customers
for monitoring performance, but it is too expensive to enable across all
sites
- Sentry has similar (but simpler) performance monitoring tools to keep
track of response times that are available to us for free, but we just
haven't configured them
- This PR sets up Sentry Performance monitoring for API requests so we
can have one place for monitoring errors + performance so we can stay on
top of response times more easily.
- Tracing is disabled by default, so there is no additional overhead
unless `sentry.tracing.enabled` is set to `true` in the site's config.
Additionally, `sentry.tracing.sampleRate` should be set to a decimal
value between 0 and 1. This value defaults to 0 to avoid accidentally
blowing through quota, and requires a value to explicitly be set in
order to send the traces to Sentry.
This commit is contained in:
Chris Raible 2023-12-06 15:04:35 -08:00 committed by GitHub
parent a87804be57
commit 1b43b5c60a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -30,7 +30,9 @@ const maintenanceMiddleware = (req, res, next) => {
const rootApp = () => {
const app = express('root');
app.use(sentry.requestHandler);
if (config.get('sentry')?.tracing?.enabled === true) {
app.use(sentry.tracingHandler);
}
app.enable('maintenance');
app.use(maintenanceMiddleware);

View file

@ -59,13 +59,22 @@ if (sentryConfig && !sentryConfig.disabled) {
const Sentry = require('@sentry/node');
const version = require('@tryghost/version').full;
const environment = config.get('env');
Sentry.init({
const sentryInitConfig = {
dsn: sentryConfig.dsn,
release: 'ghost@' + version,
environment: environment,
maxValueLength: 1000,
beforeSend: beforeSend
});
integrations: [],
beforeSend
};
// Enable tracing if sentry.tracing.enabled is true
if (sentryConfig.tracing?.enabled === true) {
sentryInitConfig.integrations.push(new Sentry.Integrations.Http({tracing: true}));
sentryInitConfig.integrations.push(new Sentry.Integrations.Express());
sentryInitConfig.tracesSampleRate = parseFloat(sentryConfig.tracing.sampleRate) || 0.0;
}
Sentry.init(sentryInitConfig);
module.exports = {
requestHandler: Sentry.Handlers.requestHandler(),
@ -82,6 +91,7 @@ if (sentryConfig && !sentryConfig.disabled) {
return (error.statusCode === 500);
}
}),
tracingHandler: Sentry.Handlers.tracingHandler(),
captureException: Sentry.captureException,
beforeSend: beforeSend
};
@ -95,6 +105,7 @@ if (sentryConfig && !sentryConfig.disabled) {
module.exports = {
requestHandler: expressNoop,
errorHandler: expressNoop,
tracingHandler: expressNoop,
captureException: noop
};
}