Added Sentry message logging for generating magic links (#20789)

ref https://linear.app/tryghost/issue/ONC-258
This commit is contained in:
Steve Larson 2024-08-19 16:28:15 -05:00 committed by Kevin Ansfield
parent 19b8674c3a
commit ad9aa47400
No known key found for this signature in database
5 changed files with 17 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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({