From 9f4bc9c13242885e644945c48313375036c068f3 Mon Sep 17 00:00:00 2001 From: Steve Larson <9larsons@gmail.com> Date: Mon, 19 Aug 2024 16:28:15 -0500 Subject: [PATCH] Added Sentry message logging for generating magic links (#20789) ref https://linear.app/tryghost/issue/ONC-258 --- ghost/core/core/server/services/members/api.js | 4 +++- .../core/server/services/newsletters/NewslettersService.js | 4 +++- .../core/server/services/settings/SettingsBREADService.js | 4 +++- ghost/magic-link/lib/MagicLink.js | 4 ++++ ghost/members-api/lib/members-api.js | 6 ++++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ghost/core/core/server/services/members/api.js b/ghost/core/core/server/services/members/api.js index 5b5757455f..30613bfe15 100644 --- a/ghost/core/core/server/services/members/api.js +++ b/ghost/core/core/server/services/members/api.js @@ -18,6 +18,7 @@ const newslettersService = require('../newsletters'); const memberAttributionService = require('../member-attribution'); const emailSuppressionList = require('../email-suppression-list'); const {t} = require('../i18n'); +const sentry = require('../../../shared/sentry'); const MAGIC_LINK_TOKEN_VALIDITY = 24 * 60 * 60 * 1000; const MAGIC_LINK_TOKEN_VALIDITY_AFTER_USAGE = 10 * 60 * 1000; @@ -234,7 +235,8 @@ function createApiInstance(config) { newslettersService: newslettersService, memberAttributionService: memberAttributionService.service, emailSuppressionList, - settingsCache + settingsCache, + sentry }); return membersApiInstance; diff --git a/ghost/core/core/server/services/newsletters/NewslettersService.js b/ghost/core/core/server/services/newsletters/NewslettersService.js index cd2ba1ea09..58f9612340 100644 --- a/ghost/core/core/server/services/newsletters/NewslettersService.js +++ b/ghost/core/core/server/services/newsletters/NewslettersService.js @@ -5,6 +5,7 @@ const verifyEmailTemplate = require('./emails/verify-email'); const debug = require('@tryghost/debug')('services:newsletters'); const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); +const sentry = require('../../../shared/sentry'); const messages = { nameAlreadyExists: 'A newsletter with the same name already exists', @@ -84,7 +85,8 @@ class NewslettersService { getSigninURL, getText, getHTML, - getSubject + getSubject, + sentry }); } diff --git a/ghost/core/core/server/services/settings/SettingsBREADService.js b/ghost/core/core/server/services/settings/SettingsBREADService.js index b3c5eb6dd3..98f02787e8 100644 --- a/ghost/core/core/server/services/settings/SettingsBREADService.js +++ b/ghost/core/core/server/services/settings/SettingsBREADService.js @@ -5,6 +5,7 @@ const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./setti const logging = require('@tryghost/logging'); const MagicLink = require('@tryghost/magic-link'); const verifyEmailTemplate = require('./emails/verify-email'); +const sentry = require('../../../shared/sentry'); const EMAIL_KEYS = ['members_support_address']; const messages = { @@ -80,7 +81,8 @@ class SettingsBREADService { getSigninURL, getText, getHTML, - getSubject + getSubject, + sentry }); } diff --git a/ghost/magic-link/lib/MagicLink.js b/ghost/magic-link/lib/MagicLink.js index b418222605..b49b25a20b 100644 --- a/ghost/magic-link/lib/MagicLink.js +++ b/ghost/magic-link/lib/MagicLink.js @@ -33,6 +33,7 @@ class MagicLink { * @param {typeof defaultGetText} [options.getText] * @param {typeof defaultGetHTML} [options.getHTML] * @param {typeof defaultGetSubject} [options.getSubject] + * @param {object} [options.sentry] */ constructor(options) { if (!options || !options.transporter || !options.tokenProvider || !options.getSigninURL) { @@ -44,6 +45,7 @@ class MagicLink { this.getText = options.getText || defaultGetText; this.getHTML = options.getHTML || defaultGetHTML; this.getSubject = options.getSubject || defaultGetSubject; + this.sentry = options.sentry || undefined; } /** @@ -57,6 +59,8 @@ class MagicLink { * @returns {Promise<{token: Token, info: SentMessageInfo}>} */ async sendMagicLink(options) { + this.sentry?.captureMessage?.(`[Magic Link] Generating magic link`, {extra: options}); + if (!isEmail(options.email)) { throw new BadRequestError({ message: tpl(messages.invalidEmail) diff --git a/ghost/members-api/lib/members-api.js b/ghost/members-api/lib/members-api.js index 00068ed53c..a726ad9eab 100644 --- a/ghost/members-api/lib/members-api.js +++ b/ghost/members-api/lib/members-api.js @@ -71,7 +71,8 @@ module.exports = function MembersAPI({ newslettersService, memberAttributionService, emailSuppressionList, - settingsCache + settingsCache, + sentry }) { const tokenService = new TokenService({ privateKey, @@ -154,7 +155,8 @@ module.exports = function MembersAPI({ getSigninURL, getText, getHTML, - getSubject + getSubject, + sentry }); const paymentsService = new PaymentsService({