From 4b472615a806e166a4df464d91f05d2e12258322 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 19 Feb 2021 09:10:45 +0000 Subject: [PATCH] Added Sentry to new boot process - With the new boot finalised it's clearer to see where this needs to go - Update comments to add more clarity around what's happening and why - Cleaned up the version require, as this was prep for maybe using version via config, which won't work in MigratorConfig --- core/app.js | 5 ++++- core/boot.js | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/app.js b/core/app.js index c79f3bb3b9..17b9dcb66f 100644 --- a/core/app.js +++ b/core/app.js @@ -1,5 +1,5 @@ +const sentry = require('./shared/sentry'); const express = require('./shared/express'); -const rootApp = express('root'); const fs = require('fs'); const path = require('path'); @@ -16,6 +16,9 @@ const maintenanceMiddleware = (req, res, next) => { fs.createReadStream(path.resolve(__dirname, './server/views/maintenance.html')).pipe(res); }; +const rootApp = express('root'); +rootApp.use(sentry.requestHandler); + rootApp.enable('maintenance'); rootApp.use(maintenanceMiddleware); diff --git a/core/boot.js b/core/boot.js index ee7e814dd3..6afc37e8e5 100644 --- a/core/boot.js +++ b/core/boot.js @@ -111,7 +111,7 @@ const mountGhost = (rootApp, ghostApp) => { }; const bootGhost = async () => { - // Metrics & debugging + // Metrics const startTime = Date.now(); let ghostServer; @@ -121,11 +121,17 @@ const bootGhost = async () => { const config = require('./shared/config'); debug('End: Load config'); + // Version is required by sentry & Migratior config & so is fundamental to booting + // However, it involves reading package.json, so put it here for visibility on how slow it is debug('Begin: Load version info'); - const version = require('./server/lib/ghost-version'); - config.set('version', version); + require('./server/lib/ghost-version'); debug('End: Load version info'); + // Sentry must be initialised early, but requires config + debug('Begin: Load sentry'); + require('./shared/sentry'); + debug('End: Load sentry'); + debug('Begin: load server + minimal app'); process.env.NODE_ENV = process.env.NODE_ENV || 'development';