mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
chore(server): add mail metrics (#7514)
This commit is contained in:
@@ -3,6 +3,7 @@ import { Inject, Injectable, Optional } from '@nestjs/common';
|
|||||||
import { Config } from '../config';
|
import { Config } from '../config';
|
||||||
import { MailerServiceIsNotConfigured } from '../error';
|
import { MailerServiceIsNotConfigured } from '../error';
|
||||||
import { URLHelper } from '../helpers';
|
import { URLHelper } from '../helpers';
|
||||||
|
import { metrics } from '../metrics';
|
||||||
import type { MailerService, Options } from './mailer';
|
import type { MailerService, Options } from './mailer';
|
||||||
import { MAILER_SERVICE } from './mailer';
|
import { MAILER_SERVICE } from './mailer';
|
||||||
import { emailTemplate } from './template';
|
import { emailTemplate } from './template';
|
||||||
@@ -19,10 +20,20 @@ export class MailService {
|
|||||||
throw new MailerServiceIsNotConfigured();
|
throw new MailerServiceIsNotConfigured();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mailer.sendMail({
|
metrics.mail.counter('total').add(1);
|
||||||
from: this.config.mailer?.from,
|
try {
|
||||||
...options,
|
const result = await this.mailer.sendMail({
|
||||||
});
|
from: this.config.mailer?.from,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
metrics.mail.counter('sent').add(1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
metrics.mail.counter('error').add(1);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConfigured() {
|
hasConfigured() {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export type KnownMetricScopes =
|
|||||||
| 'auth'
|
| 'auth'
|
||||||
| 'controllers'
|
| 'controllers'
|
||||||
| 'doc'
|
| 'doc'
|
||||||
| 'sse';
|
| 'sse'
|
||||||
|
| 'mail';
|
||||||
|
|
||||||
const metricCreators: MetricCreators = {
|
const metricCreators: MetricCreators = {
|
||||||
counter(meter: Meter, name: string, opts?: MetricOptions) {
|
counter(meter: Meter, name: string, opts?: MetricOptions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user