Skip to content

Commit

Permalink
Added Sentry message logging for generating magic links (#20789)
Browse files Browse the repository at this point in the history
  • Loading branch information
9larsons authored and kevinansfield committed Aug 20, 2024
1 parent 19b8674 commit ad9aa47
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ghost/core/core/server/services/members/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -234,7 +235,8 @@ function createApiInstance(config) {
newslettersService: newslettersService,
memberAttributionService: memberAttributionService.service,
emailSuppressionList,
settingsCache
settingsCache,
sentry
});

return membersApiInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -84,7 +85,8 @@ class NewslettersService {
getSigninURL,
getText,
getHTML,
getSubject
getSubject,
sentry
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -80,7 +81,8 @@ class SettingsBREADService {
getSigninURL,
getText,
getHTML,
getSubject
getSubject,
sentry
});
}

Expand Down
4 changes: 4 additions & 0 deletions ghost/magic-link/lib/MagicLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions ghost/members-api/lib/members-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ module.exports = function MembersAPI({
newslettersService,
memberAttributionService,
emailSuppressionList,
settingsCache
settingsCache,
sentry
}) {
const tokenService = new TokenService({
privateKey,
Expand Down Expand Up @@ -154,7 +155,8 @@ module.exports = function MembersAPI({
getSigninURL,
getText,
getHTML,
getSubject
getSubject,
sentry
});

const paymentsService = new PaymentsService({
Expand Down

0 comments on commit ad9aa47

Please sign in to comment.