feat: git hash on error (#9373)

This commit is contained in:
Tony
2022-03-23 17:10:47 +00:00
committed by GitHub
parent 6ba0cb246e
commit baeafb97a5
2 changed files with 9 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ const path = require('path');
const { RequestInProgressError } = require('@/errors');
let Sentry;
let gitHash;
if (config.sentry.dsn) {
Sentry = Sentry || require('@sentry/node');
@@ -19,6 +20,12 @@ if (config.sentry.dsn) {
logger.info('Sentry inited.');
}
try {
gitHash = require('git-rev-sync').short();
} catch (e) {
gitHash = (process.env.HEROKU_SLUG_COMMIT && process.env.HEROKU_SLUG_COMMIT.slice(0, 7)) || (process.env.VERCEL_GITHUB_COMMIT_SHA && process.env.VERCEL_GITHUB_COMMIT_SHA.slice(0, 7)) || 'unknown';
}
module.exports = async (ctx, next) => {
try {
const time = +new Date();
@@ -68,6 +75,7 @@ module.exports = async (ctx, next) => {
message,
errorPath: ctx.path,
nodeVersion: process.version,
gitHash,
});
}