mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added metric for sending transactional email with mailgun
refs: https://github.com/TryGhost/Toolbox/issues/439 This case completes the monitoring of mailgun.js usage within Ghost.
This commit is contained in:
parent
168fa64395
commit
0c18060f61
1 changed files with 17 additions and 1 deletions
|
@ -7,6 +7,7 @@ const errors = require('@tryghost/errors');
|
||||||
const tpl = require('@tryghost/tpl');
|
const tpl = require('@tryghost/tpl');
|
||||||
const settingsCache = require('../../../shared/settings-cache');
|
const settingsCache = require('../../../shared/settings-cache');
|
||||||
const urlUtils = require('../../../shared/url-utils');
|
const urlUtils = require('../../../shared/url-utils');
|
||||||
|
const metrics = require('@tryghost/metrics');
|
||||||
const messages = {
|
const messages = {
|
||||||
title: 'Ghost at {domain}',
|
title: 'Ghost at {domain}',
|
||||||
checkEmailConfigInstructions: 'Please see {url} for instructions on configuring email.',
|
checkEmailConfigInstructions: 'Please see {url} for instructions on configuring email.',
|
||||||
|
@ -83,7 +84,8 @@ module.exports = class GhostMailer {
|
||||||
const options = config.get('mail') && _.clone(config.get('mail').options) || {};
|
const options = config.get('mail') && _.clone(config.get('mail').options) || {};
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
usingDirect: transport === 'direct'
|
usingDirect: transport === 'direct',
|
||||||
|
usingMailgun: transport === 'mailgun'
|
||||||
};
|
};
|
||||||
this.transport = nodemailer(transport, options);
|
this.transport = nodemailer(transport, options);
|
||||||
}
|
}
|
||||||
|
@ -121,10 +123,24 @@ module.exports = class GhostMailer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMail(message) {
|
async sendMail(message) {
|
||||||
|
const startTime = Date.now();
|
||||||
try {
|
try {
|
||||||
const response = await this.transport.sendMail(message);
|
const response = await this.transport.sendMail(message);
|
||||||
|
if (this.state.usingMailgun) {
|
||||||
|
metrics.metric('mailgun-send-transactional-mail', {
|
||||||
|
value: Date.now() - startTime,
|
||||||
|
statusCode: 200
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (this.state.usingMailgun) {
|
||||||
|
metrics.metric('mailgun-send-transactional-mail', {
|
||||||
|
value: Date.now() - startTime,
|
||||||
|
statusCode: err.status
|
||||||
|
});
|
||||||
|
}
|
||||||
throw createMailError({
|
throw createMailError({
|
||||||
message: tpl(messages.reason, {reason: err.message || err}),
|
message: tpl(messages.reason, {reason: err.message || err}),
|
||||||
err
|
err
|
||||||
|
|
Loading…
Add table
Reference in a new issue