Skip to content

Commit 21fd836

Browse files
committed
task(many): Record start up messages to valid sentry config
Because: - We want to make sure all crons, queue processors, and services are instrumented with Sentry This Commit: - Goes through each FxA process and makes sure sentry is initialized - Captures start up message so we can keep tabs on processes
1 parent f8d3edc commit 21fd836

12 files changed

Lines changed: 141 additions & 27 deletions

File tree

packages/fxa-admin-panel/server/lib/server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,12 @@ export async function createServer() {
155155
logger.info('server.starting', { port });
156156
app.listen(port, host, () => {
157157
logger.info('server.started', { port });
158+
Sentry.captureMessage('Admin panel server started', {
159+
level: 'info',
160+
tags: {
161+
service: 'fxa-admin-panel',
162+
env: config.get('env'),
163+
},
164+
});
158165
});
159166
}

packages/fxa-admin-server/src/scripts/audit-tokens.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import program from 'commander';
66
import { StatsD } from 'hot-shots';
77
import * as Sentry from '@sentry/node';
8+
import { initSentry } from 'fxa-shared/sentry/node';
89
import {
910
setupAuthDatabase,
1011
setupDatabase,
@@ -42,11 +43,11 @@ function getKnex(table: string) {
4243
}
4344
}
4445

45-
Sentry.init({});
46-
4746
const logFactory = mozlog(config.log);
4847
let log: ILogger = logFactory('default');
4948

49+
initSentry({ ...config, release: packageJson.version }, log);
50+
5051
//#region Table Definitions
5152
/** Defines table and key column */
5253
type TargetTable = { name: string; keyCol: string };
@@ -243,8 +244,8 @@ export async function auditRowCounts(table: string) {
243244
table_rows AS table_size
244245
FROM INFORMATION_SCHEMA.TABLES
245246
WHERE table_schema = '${table.split('.')[0]}' and table_name = '${
246-
table.split('.')[1]
247-
}'
247+
table.split('.')[1]
248+
}'
248249
`;
249250
}
250251

@@ -310,11 +311,11 @@ export async function auditOrphanedRows(
310311
COUNT(IF(parent.${parent.keyCol} is NULL, 1, NULL)) AS total_missing
311312
FROM
312313
(SELECT ${child.keyCol} FROM ${child.name} ${buildLimit(
313-
child.name
314-
)}) as child
314+
child.name
315+
)}) as child
315316
LEFT JOIN ${parent.name} parent ON child.${child.keyCol} = parent.${
316-
parent.keyCol
317-
}
317+
parent.keyCol
318+
}
318319
${buildLimit(child.name)}
319320
) AS missing;
320321
`;
@@ -481,6 +482,14 @@ export async function run() {
481482
if (require.main === module) {
482483
process.on('exit', (code) => log.info('exit', { code }));
483484

485+
Sentry.captureMessage('Audit tokens started', {
486+
level: 'info',
487+
tags: {
488+
service: 'fxa-admin-server',
489+
env: config.env,
490+
},
491+
});
492+
484493
const checkInId = Sentry.captureCheckIn({
485494
monitorSlug: 'audit-tokens',
486495
status: 'in_progress',

packages/fxa-auth-server/scripts/cleanup-old-carts.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
import program from 'commander';
5+
import * as Sentry from '@sentry/node';
6+
import { initSentry } from 'fxa-shared/sentry/node';
57

68
import { setupProcessingTaskObjects } from '../lib/payments/processing-tasks-setup';
79
import { CartCleanup } from './cleanup-old-carts/cleanup-old-carts';
@@ -27,7 +29,10 @@ const parseDeleteBeforeDays = (deleteBeforeDays: string | number) => {
2729
return null;
2830
}
2931
const date = new Date();
30-
const days = typeof deleteBeforeDays === "string" ? parseInt(deleteBeforeDays) : deleteBeforeDays;
32+
const days =
33+
typeof deleteBeforeDays === 'string'
34+
? parseInt(deleteBeforeDays)
35+
: deleteBeforeDays;
3136

3237
date.setDate(date.getDate() - days);
3338
if (!date.getTime()) {
@@ -52,7 +57,10 @@ const parseAnonymizeBeforeDays = (anonymizeBeforeDays: string | number) => {
5257
return null;
5358
}
5459
const date = new Date();
55-
const days = typeof anonymizeBeforeDays === "string" ? parseInt(anonymizeBeforeDays) : anonymizeBeforeDays;
60+
const days =
61+
typeof anonymizeBeforeDays === 'string'
62+
? parseInt(anonymizeBeforeDays)
63+
: anonymizeBeforeDays;
5664

5765
date.setDate(date.getDate() - days);
5866
if (!date.getTime()) {
@@ -103,18 +111,29 @@ async function init() {
103111
)
104112
.parse(process.argv);
105113

106-
const { config } = await setupProcessingTaskObjects('cleanup-old-carts');
114+
const { config, log } = await setupProcessingTaskObjects('cleanup-old-carts');
115+
116+
initSentry({ ...config, release: pckg.version }, log);
117+
Sentry.captureMessage('Cleanup old carts started', {
118+
level: 'info',
119+
tags: {
120+
service: 'fxa-auth-server',
121+
env: config.env,
122+
},
123+
});
107124

108125
const database = await setupAccountDatabase(config.database.mysql.auth);
109126

110-
const deleteBefore = parseDeleteBefore(program.deleteBefore) || parseDeleteBeforeDays(program.deleteBeforeDays);
111-
const anonymizeBefore = parseAnonymizeBefore(program.anonymizeBefore) || parseAnonymizeBeforeDays(program.anonymizeBeforeDays);
127+
const deleteBefore =
128+
parseDeleteBefore(program.deleteBefore) ||
129+
parseDeleteBeforeDays(program.deleteBeforeDays);
130+
const anonymizeBefore =
131+
parseAnonymizeBefore(program.anonymizeBefore) ||
132+
parseAnonymizeBeforeDays(program.anonymizeBeforeDays);
112133
const anonymizeFields = parseAnonymizeFields(program.anonymizeFields);
113134

114135
if (!deleteBefore) {
115-
throw new Error(
116-
'--delete-before or --delete-before-days is required'
117-
);
136+
throw new Error('--delete-before or --delete-before-days is required');
118137
}
119138

120139
if (anonymizeBefore && !anonymizeFields) {

packages/fxa-auth-server/scripts/delete-inactive-accounts/enqueue-inactive-account-deletions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import os from 'os';
3232
import path from 'path';
3333
import { promisify } from 'util';
3434

35+
import * as Sentry from '@sentry/node';
36+
import { initSentry } from 'fxa-shared/sentry/node';
3537
import { Command } from 'commander';
3638
import { StatsD } from 'hot-shots';
3739
import { Container } from 'typedi';
@@ -266,6 +268,17 @@ const init = async () => {
266268
const log = initLog({
267269
...config.log,
268270
});
271+
272+
const pckg = require('../../package.json');
273+
initSentry({ ...config, release: pckg.version }, log);
274+
Sentry.captureMessage('Enqueue inactive account deletions started', {
275+
level: 'info',
276+
tags: {
277+
service: 'fxa-auth-server',
278+
env: config.env,
279+
},
280+
});
281+
269282
const glean = gleanMetrics(config);
270283

271284
const redis = initRedis(

packages/fxa-auth-server/scripts/paypal-processor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ export async function init() {
6262
const lockDuration =
6363
parseInt(`${program.lockDuration}`) || DEFAULT_LOCK_DURATION_MS;
6464

65-
const { log, database, senders } = await setupProcessingTaskObjects(
66-
'paypal-processor'
67-
);
65+
const { log, database, senders } =
66+
await setupProcessingTaskObjects('paypal-processor');
6867

6968
initSentry(
7069
{
@@ -74,6 +73,14 @@ export async function init() {
7473
log
7574
);
7675

76+
Sentry.captureMessage('PayPal processor started', {
77+
level: 'info',
78+
tags: {
79+
service: 'fxa-auth-server',
80+
env: config.env,
81+
},
82+
});
83+
7784
const statsd = Container.get(StatsD);
7885
const paypalClient = new PayPalClient(
7986
config.subscriptions.paypalNvpSigCredentials,

packages/fxa-auth-server/scripts/prune-tokens.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { setupDatabase } from 'fxa-shared/db';
77
import { BaseAuthModel } from 'fxa-shared/db/models/auth';
88
import { StatsD } from 'hot-shots';
99
import * as Sentry from '@sentry/node';
10+
import { initSentry } from 'fxa-shared/sentry/node';
1011
import moment from 'moment';
1112
import { SessionToken } from 'fxa-shared/db/models/auth/session-token';
1213
const { PruneTokens } = require('fxa-shared/db/models/auth');
@@ -27,7 +28,7 @@ function parseDuration(duration: string | number) {
2728
const config = require('../config').default.getProperties();
2829
const statsd = new StatsD(config.statsd);
2930
const log = require('../lib/log')(config.log.level, 'prune-tokens', statsd);
30-
Sentry.init({});
31+
initSentry({ ...config, release: pckg.version }, log);
3132

3233
export async function init() {
3334
// Setup utilities
@@ -270,9 +271,8 @@ Exit Codes:
270271
// don't exist in the sql database anymore.
271272
const orphanedTokens = new Array<string>();
272273
for (const redisSessionTokenId of redisSessionTokenIds) {
273-
const dbSessionTokens = await SessionToken.findByTokenId(
274-
redisSessionTokenId
275-
);
274+
const dbSessionTokens =
275+
await SessionToken.findByTokenId(redisSessionTokenId);
276276
if (dbSessionTokens === null) {
277277
orphanedTokens.push(redisSessionTokenId);
278278
}
@@ -300,6 +300,14 @@ if (require.main === module) {
300300
log.info('exit', { code });
301301
});
302302

303+
Sentry.captureMessage('Prune tokens started', {
304+
level: 'info',
305+
tags: {
306+
service: 'fxa-auth-server',
307+
env: config.env,
308+
},
309+
});
310+
303311
const checkInId = Sentry.captureCheckIn({
304312
monitorSlug: 'prune-tokens',
305313
status: 'in_progress',

packages/fxa-auth-server/scripts/recorded-future/check-and-reset.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import crypto from 'crypto';
2525
import { promisify } from 'util';
2626

27+
import * as Sentry from '@sentry/node';
28+
import { initSentry } from 'fxa-shared/sentry/node';
2729
import { Command } from 'commander';
2830
import { Container } from 'typedi';
2931
import { StatsD } from 'hot-shots';
@@ -81,6 +83,9 @@ const client = createClient<paths>({
8183
Container.set(AppConfig, config);
8284
Container.set(StatsD, statsd);
8385

86+
const pckg = require('../../package.json');
87+
initSentry({ ...config, release: pckg.version }, log);
88+
8489
let authDb: Awaited<ReturnType<typeof DB.connect>> | null;
8590

8691
const checkAndReset = async () => {
@@ -419,6 +424,14 @@ async function getHasTotp2faFn() {
419424
}
420425

421426
if (require.main === module) {
427+
Sentry.captureMessage('Recorded Future check-and-reset started', {
428+
level: 'info',
429+
tags: {
430+
service: 'fxa-auth-server',
431+
env: config.env,
432+
},
433+
});
434+
422435
checkAndReset()
423436
.then(
424437
(exitCode) => {

packages/fxa-auth-server/scripts/subscription-reminders.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StatsD } from 'hot-shots';
66
import Container from 'typedi';
77
import { promisify } from 'util';
88
import * as Sentry from '@sentry/node';
9+
import { initSentry } from 'fxa-shared/sentry/node';
910

1011
import { setupProcessingTaskObjects } from '../lib/payments/processing-tasks-setup';
1112
import { SubscriptionReminders } from '../lib/payments/subscription-reminders';
@@ -25,8 +26,6 @@ const DEFAULT_ENDING_REMINDER_DAILY_LENGTH = 0;
2526
const DEFAULT_ENDING_REMINDER_MONTHLY_LENGTH = 7;
2627
const DEFAULT_ENDING_REMINDER_YEARLY_LENGTH = 14;
2728

28-
Sentry.init({});
29-
3029
async function init() {
3130
program
3231
.version(pckg.version)
@@ -70,6 +69,16 @@ async function init() {
7069

7170
const { log, database, senders, stripeHelper, config } =
7271
await setupProcessingTaskObjects('subscription-reminders');
72+
73+
initSentry({ ...config, release: pckg.version }, log);
74+
Sentry.captureMessage('Subscription reminders started', {
75+
level: 'info',
76+
tags: {
77+
service: 'fxa-auth-server',
78+
env: config.env,
79+
},
80+
});
81+
7382
await initSubplat({
7483
loggerName: 'subscription-reminders',
7584
legacyLog: log,

packages/fxa-auth-server/scripts/verification-reminders.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const verificationReminders = require('../lib/verification-reminders')(
2525
config
2626
);
2727
const Sentry = require('@sentry/node');
28+
const { initSentry } = require('fxa-shared/sentry/node');
29+
const pckg = require('../package.json');
2830
const cadReminders = require('../lib/cad-reminders')(config, log);
2931
const subscriptionAccountReminders =
3032
require('../lib/subscription-account-reminders')(log, config);
@@ -37,8 +39,14 @@ const { FxaMailer } = require('../lib/senders/fxa-mailer');
3739
const { FxaMailerFormat } = require('../lib/senders/fxa-mailer-format');
3840
const { StatsD } = require('hot-shots');
3941

40-
41-
Sentry.init({});
42+
initSentry({ ...config, release: pckg.version }, log);
43+
Sentry.captureMessage('Verification reminders started', {
44+
level: 'info',
45+
tags: {
46+
service: 'fxa-auth-server',
47+
env: config.env,
48+
},
49+
});
4250
const checkInId = Sentry.captureCheckIn({
4351
monitorSlug: 'verification-reminders',
4452
status: 'in_progress',

packages/fxa-content-server/server/bin/fxa-content-server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
// Initializes sentry
1010
require('../lib/sentry');
11+
const Sentry = require('@sentry/node');
1112

1213
// setup version first for the rest of the modules
1314
const loggerFactory = require('../lib/logging/log');
@@ -296,6 +297,13 @@ function listen(theApp) {
296297
config.get('scopedKeys.validation')
297298
)}`
298299
);
300+
Sentry.captureMessage('Content server started', {
301+
level: 'info',
302+
tags: {
303+
service: 'fxa-content-server',
304+
env: config.get('env'),
305+
},
306+
});
299307
}
300308
return true;
301309
}

0 commit comments

Comments
 (0)