(sentry) send deployment information to track which environment is on which release

This commit is contained in:
Valentyne Stigloher 2024-03-11 20:56:38 +01:00
parent 7d478b0dd6
commit ff716a3d41
3 changed files with 36 additions and 0 deletions

View File

@ -37,6 +37,7 @@ deploy: install
yarn ts-node server/migrate.ts
ln -sfn ../data/img ./static/img-local
ln -sfn ../data/docs ./static/docs-local
yarn ts-node server/sentry.ts
switch:
rm -rf cache

View File

@ -226,6 +226,7 @@ const nuxtConfig: NuxtConfig = {
telemetry: false,
},
config: {
environment: process.env.NODE_ENV === 'production' ? config.locale : process.env.NODE_ENV!,
attachStacktrace: true,
initialScope(scope) {
scope.setTag('locale', process.env.LOCALE);

34
server/sentry.ts Normal file
View File

@ -0,0 +1,34 @@
import fs from 'fs';
import SentryCli from '@sentry/cli';
import './setup.ts';
import { loadSuml } from './loader.ts';
import allLocales from '../locale/locales.ts';
import type { Config } from '../locale/config.ts';
const __dirname = new URL('.', import.meta.url).pathname;
async function notifyDeployment(): Promise<void> {
if (!process.env.SENTRY_DSN) {
process.stdout.write('SENTRY_DSN is not defined, skipping deployment information to Sentry');
return;
}
const version = fs.readFileSync(`${__dirname}/../cache/version`, 'utf-8');
const config = loadSuml('config') as Config;
const sentryCli = new SentryCli();
await sentryCli.releases.setCommits(version, {
auto: true,
});
await sentryCli.releases.finalize(version);
const environment = process.env.NODE_ENV === 'production' ? config.locale : process.env.NODE_ENV!;
await sentryCli.releases.newDeploy(version, {
env: environment,
url: allLocales.find((locale) => locale.code === config.locale)?.url,
});
process.stdout.write(`Sent deployment information for environment ${environment} to Sentry`);
}
await notifyDeployment();