Improve sentry error analytics and startup message

This commit is contained in:
Alexandre Bodin 2019-10-15 16:21:59 +02:00
parent 85cd288526
commit 0367a55751
8 changed files with 182 additions and 108 deletions

View File

@ -7,7 +7,7 @@ const execa = require('execa');
const ora = require('ora');
const stopProcess = require('./utils/stop-process');
const { trackUsage, captureError } = require('./utils/usage');
const { trackUsage, captureStderr } = require('./utils/usage');
const packageJSON = require('./resources/json/package.json');
const databaseJSON = require('./resources/json/database.json.js');
@ -100,15 +100,10 @@ module.exports = async function createProject(
error: error.stderr.slice(-1024),
});
console.error(`${chalk.red('Error')} while installing dependencies:`);
error.stderr
.trim()
.split('\n')
.forEach(line => {
console.error(line);
});
console.log(`${chalk.red('Error')} while installing dependencies:`);
console.log(error.stderr);
await captureError(new Error('didNotInstallProjectDependencies'));
await captureStderr('didNotInstallProjectDependencies', error);
stopProcess('Stopping installation');
}

View File

@ -3,7 +3,7 @@
const execa = require('execa');
const stopProcess = require('./utils/stop-process');
const { trackUsage, captureError } = require('./utils/usage');
const { trackUsage, captureStderr } = require('./utils/usage');
const defaultConfigs = require('./utils/db-configs.js');
const clientDependencies = require('./utils/db-client-dependencies.js');
const createProject = require('./create-project');
@ -43,16 +43,8 @@ module.exports = async function createQuickStartProject(scope) {
error: error.stderr.slice(-1024),
});
error.stderr
.trim()
.split('\n')
.forEach(line => {
console.error(line);
});
await captureError(new Error('didNotBuildAdmin'));
stopProcess('Stopping');
await captureStderr('didNotBuildAdmin', error);
process.exit(1);
}
console.log(`Running your Strapi application.`);
@ -74,15 +66,7 @@ module.exports = async function createQuickStartProject(scope) {
error: error.stderr.slice(-1024),
});
error.stderr
.trim()
.split('\n')
.forEach(line => {
console.error(line);
});
await captureError(new Error('didNotStartServer'));
stopProcess('Stopping');
await captureStderr('didNotStartServer', error);
process.exit(1);
}
};

View File

@ -10,7 +10,7 @@ const sentry = require('@sentry/node');
const hasYarn = require('./utils/has-yarn');
const checkRequirements = require('./utils/check-requirements');
const { trackError, captureError } = require('./utils/usage');
const { trackError, captureException } = require('./utils/usage');
const parseDatabaseArguments = require('./utils/parse-db-arguments');
const generateNew = require('./generate-new');
@ -81,7 +81,7 @@ module.exports = (projectDirectory, cliArguments) => {
return generateNew(scope).catch(error => {
console.error(error);
return captureError(new Error('didNotCreateProject')).then(() => {
return captureException(error).then(() => {
return trackError({ scope, error }).then(() => {
process.exit(1);
});

View File

@ -4,7 +4,7 @@ const os = require('os');
const fetch = require('node-fetch');
const sentry = require('@sentry/node');
async function captureError(error) {
async function captureException(error) {
try {
sentry.captureException(error);
await sentry.flush();
@ -14,6 +14,33 @@ async function captureError(error) {
}
}
async function captureError(message) {
try {
sentry.captureMessage(message, 'error');
await sentry.flush();
} catch (err) {
/** ignore errors*/
return Promise.resolve();
}
}
function captureStderr(name, error) {
if (error && error.stderr && error.stderr.trim() !== '') {
error.stderr
.trim()
.split('\n')
.forEach(line => {
sentry.addBreadcrumb({
category: 'stderr',
message: line,
level: 'error',
});
});
}
return captureError(name);
}
function trackEvent(event, body) {
try {
return fetch('https://analytics.strapi.io/track', {
@ -74,5 +101,6 @@ function trackUsage({ event, scope, error }) {
module.exports = {
trackError,
trackUsage,
captureError,
captureException,
captureStderr,
};

View File

@ -13,7 +13,7 @@
"lib": "./lib"
},
"dependencies": {
"@sentry/node": "5.6.2",
"@sentry/node": "^5.7.1",
"execa": "^1.0.0",
"fs-extra": "^8.0.1",
"inquirer": "^6.3.1",

View File

@ -9,6 +9,9 @@ const Koa = require('koa');
const Router = require('koa-router');
const _ = require('lodash');
const { logger, models } = require('strapi-utils');
const chalk = require('chalk');
const CLITable = require('cli-table3');
const utils = require('./utils');
const {
loadConfig,
@ -141,6 +144,71 @@ class Strapi extends EventEmitter {
}
}
logStats() {
const columns = Math.min(process.stderr.columns, 80) - 2;
console.log();
console.log(chalk.black.bgWhite(_.padEnd(' Project information', columns)));
console.log();
const infoTable = new CLITable({
colWidths: [20, 50],
chars: { mid: '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
});
infoTable.push(
[chalk.blue('Time'), `${new Date()}`],
[chalk.blue('Launched in'), Date.now() - this.config.launchedAt + ' ms'],
[chalk.blue('Environment'), this.config.environment],
[chalk.blue('Process PID'), process.pid],
[
chalk.blue('Version'),
`${this.config.info.strapi} (node v${this.config.info.node})`,
]
);
console.log(infoTable.toString());
console.log();
console.log(chalk.black.bgWhite(_.padEnd(' Actions available', columns)));
console.log();
}
logFirstStartupMessage() {
this.logStats();
console.log(chalk.bold('One more thing...'));
console.log(
chalk.grey(
'Create your first administrator 💻 by going to the administration panel at:'
)
);
console.log();
const addressTable = new CLITable();
addressTable.push([chalk.bold(this.config.admin.url)]);
console.log(`${addressTable.toString()}`);
console.log();
}
logStartupMessage() {
this.logStats();
console.log(chalk.bold('Welcome back!'));
if (this.config.serveAdminPanel === true) {
console.log(
chalk.grey(
'To manage your project 🚀, go to the administration panel at:'
)
);
console.log(chalk.bold(this.config.admin.url));
console.log();
}
console.log(chalk.grey('To access the server ⚡️, go to:'));
console.log(chalk.bold(this.config.url));
console.log();
}
async start(cb) {
try {
// Emit starting event.
@ -160,23 +228,11 @@ class Strapi extends EventEmitter {
this.server.listen(this.config.port, async err => {
if (err) return this.stopWithError(err);
this.log.info('Time: ' + new Date());
this.log.info(
'Launched in: ' + (Date.now() - this.config.launchedAt) + ' ms'
);
this.log.info('Environment: ' + this.config.environment);
this.log.info('Process PID: ' + process.pid);
this.log.info(
`Version: ${this.config.info.strapi} (node v${this.config.info.node})`
);
this.log.info('To shut down your server, press <CTRL> + C at any time');
console.log();
if (this.config.serveAdminPanel === true) {
this.log.info(`☄️ Admin panel: ${this.config.admin.url}`);
if (this.config.init) {
this.logFirstStartupMessage();
} else {
this.logStartupMessage();
}
this.log.info(`⚡️ Server: ${this.config.url}`);
console.log();
// Emit started event.
this.emit('server:started');

View File

@ -17,6 +17,7 @@
"boom": "^7.3.0",
"chalk": "^2.4.1",
"chokidar": "^2.1.2",
"cli-table3": "^0.5.1",
"cross-spawn": "^6.0.5",
"delegates": "^1.0.0",
"execa": "^1.0.0",

124
yarn.lock
View File

@ -2074,60 +2074,60 @@
"@sendgrid/client" "^6.4.0"
"@sendgrid/helpers" "^6.4.0"
"@sentry/core@5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.6.2.tgz#8c5477654a83ebe41a72e86a79215deb5025e418"
integrity sha512-grbjvNmyxP5WSPR6UobN2q+Nss7Hvz+BClBT8QTr7VTEG5q89TwNddn6Ej3bGkaUVbct/GpVlI3XflWYDsnU6Q==
"@sentry/core@5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.7.1.tgz#3eb2b7662cac68245931ee939ec809bf7a639d0e"
integrity sha512-AOn3k3uVWh2VyajcHbV9Ta4ieDIeLckfo7UMLM+CTk2kt7C89SayDGayJMSsIrsZlL4qxBoLB9QY4W2FgAGJrg==
dependencies:
"@sentry/hub" "5.6.1"
"@sentry/minimal" "5.6.1"
"@sentry/types" "5.6.1"
"@sentry/utils" "5.6.1"
"@sentry/hub" "5.7.1"
"@sentry/minimal" "5.7.1"
"@sentry/types" "5.7.1"
"@sentry/utils" "5.7.1"
tslib "^1.9.3"
"@sentry/hub@5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.6.1.tgz#9f355c0abcc92327fbd10b9b939608aa4967bece"
integrity sha512-m+OhkIV5yTAL3R1+XfCwzUQka0UF/xG4py8sEfPXyYIcoOJ2ZTX+1kQJLy8QQJ4RzOBwZA+DzRKP0cgzPJ3+oQ==
"@sentry/hub@5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.7.1.tgz#a52acd9fead7f3779d96e9965c6978aecc8b9cad"
integrity sha512-evGh323WR073WSBCg/RkhlUmCQyzU0xzBzCZPscvcoy5hd4SsLE6t9Zin+WACHB9JFsRQIDwNDn+D+pj3yKsig==
dependencies:
"@sentry/types" "5.6.1"
"@sentry/utils" "5.6.1"
"@sentry/types" "5.7.1"
"@sentry/utils" "5.7.1"
tslib "^1.9.3"
"@sentry/minimal@5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.6.1.tgz#09d92b26de0b24555cd50c3c33ba4c3e566009a1"
integrity sha512-ercCKuBWHog6aS6SsJRuKhJwNdJ2oRQVWT2UAx1zqvsbHT9mSa8ZRjdPHYOtqY3DoXKk/pLUFW/fkmAnpdMqRw==
"@sentry/minimal@5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.7.1.tgz#56afc537737586929e25349765e37a367958c1e1"
integrity sha512-nS/Dg+jWAZtcxQW8wKbkkw4dYvF6uyY/vDiz/jFCaux0LX0uhgXAC9gMOJmgJ/tYBLJ64l0ca5LzpZa7BMJQ0g==
dependencies:
"@sentry/hub" "5.6.1"
"@sentry/types" "5.6.1"
"@sentry/hub" "5.7.1"
"@sentry/types" "5.7.1"
tslib "^1.9.3"
"@sentry/node@5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-5.6.2.tgz#4b62f056031da65cad78220d48c546b8bfbfaed7"
integrity sha512-A9CELco6SjF4zt8iS1pO3KdUVI2WVhtTGhSH6X04OVf2en1fimPR+Vs8YVY/04udwd7o+3mI6byT+rS9+/Qzow==
"@sentry/node@^5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-5.7.1.tgz#94e2fbac94f6cc061be3bc14b22813536c59698d"
integrity sha512-hVM10asFStrOhYZzMqFM7V1lrHkr1ydc2n/SFG0ZmIQxfTjCVElyXV/BJASIdqadM1fFIvvtD/EfgkTcZmub1g==
dependencies:
"@sentry/core" "5.6.2"
"@sentry/hub" "5.6.1"
"@sentry/types" "5.6.1"
"@sentry/utils" "5.6.1"
cookie "0.3.1"
https-proxy-agent "2.2.1"
lru_map "0.3.3"
"@sentry/core" "5.7.1"
"@sentry/hub" "5.7.1"
"@sentry/types" "5.7.1"
"@sentry/utils" "5.7.1"
cookie "^0.3.1"
https-proxy-agent "^3.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"
"@sentry/types@5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.6.1.tgz#5915e1ee4b7a678da3ac260c356b1cb91139a299"
integrity sha512-Kub8TETefHpdhvtnDj3kKfhCj0u/xn3Zi2zIC7PB11NJHvvPXENx97tciz4roJGp7cLRCJsFqCg4tHXniqDSnQ==
"@sentry/types@5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.7.1.tgz#4c4c1d4d891b6b8c2c3c7b367d306a8b1350f090"
integrity sha512-tbUnTYlSliXvnou5D4C8Zr+7/wJrHLbpYX1YkLXuIJRU0NSi81bHMroAuHWILcQKWhVjaV/HZzr7Y/hhWtbXVQ==
"@sentry/utils@5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.6.1.tgz#69d9e151e50415bc91f2428e3bcca8beb9bc2815"
integrity sha512-rfgha+UsHW816GqlSRPlniKqAZylOmQWML2JsujoUP03nPu80zdN43DK9Poy/d9OxBxv0gd5K2n+bFdM2kqLQQ==
"@sentry/utils@5.7.1":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.7.1.tgz#cf37ad55f78e317665cd8680f202d307fa77f1d0"
integrity sha512-nhirUKj/qFLsR1i9kJ5BRvNyzdx/E2vorIsukuDrbo8e3iZ11JMgCOVrmC8Eq9YkHBqgwX4UnrPumjFyvGMZ2Q==
dependencies:
"@sentry/types" "5.6.1"
"@sentry/types" "5.7.1"
tslib "^1.9.3"
"@sheerun/mutationobserver-shim@^0.3.2":
@ -3037,7 +3037,7 @@ addressparser@1.0.1:
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-1.0.1.tgz#47afbe1a2a9262191db6838e4fd1d39b40821746"
integrity sha1-R6++GiqSYhkdtoOOT9HTm0CCF0Y=
agent-base@4, agent-base@^4.1.0, agent-base@^4.2.0, agent-base@^4.3.0:
agent-base@4, agent-base@^4.2.0, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
@ -4780,6 +4780,16 @@ cli-spinners@^2.0.0:
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.2.0.tgz#e8b988d9206c692302d8ee834e7a85c0144d8f77"
integrity sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==
cli-table3@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.5.1.tgz#0252372d94dfc40dbd8df06005f48f31f656f202"
integrity sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw==
dependencies:
object-assign "^4.1.0"
string-width "^2.1.1"
optionalDependencies:
colors "^1.1.2"
cli-truncate@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-0.2.1.tgz#9f15cfbb0705005369216c626ac7d05ab90dd574"
@ -4967,7 +4977,7 @@ colorette@1.1.0:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.1.0.tgz#1f943e5a357fac10b4e0f5aaef3b14cdc1af6ec7"
integrity sha512-6S062WDQUXi6hOfkO/sBPVwE5ASXY4G2+b4atvhJfSsuUUhIaUKlkjLe9692Ipyt5/a+IPF5aVTu3V5gvXq5cg==
colors@^1.3.3:
colors@^1.1.2, colors@^1.3.3:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
@ -5317,16 +5327,16 @@ cookie-signature@1.0.6:
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw=
cookie@0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=
cookie@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba"
integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==
cookie@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=
cookies@~0.7.1:
version "0.7.3"
resolved "https://registry.yarnpkg.com/cookies/-/cookies-0.7.3.tgz#7912ce21fbf2e8c2da70cf1c3f351aecf59dadfa"
@ -9041,14 +9051,6 @@ https-browserify@^1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=
https-proxy-agent@2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
dependencies:
agent-base "^4.1.0"
debug "^3.1.0"
https-proxy-agent@^2.2.1:
version "2.2.2"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz#271ea8e90f836ac9f119daccd39c19ff7dfb0793"
@ -9057,6 +9059,14 @@ https-proxy-agent@^2.2.1:
agent-base "^4.3.0"
debug "^3.1.0"
https-proxy-agent@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-3.0.0.tgz#0106efa5d63d6d6f3ab87c999fa4877a3fd1ff97"
integrity sha512-y4jAxNEihqvBI5F3SaO2rtsjIOnnNA8sEbuiP+UhJZJHeM2NRm6c09ax2tgqme+SgUUvjao2fJXF4h3D6Cb2HQ==
dependencies:
agent-base "^4.3.0"
debug "^3.1.0"
humanize-ms@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed"
@ -11722,7 +11732,7 @@ lru-cache@^5.0.0, lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"
lru_map@0.3.3:
lru_map@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
@ -14949,7 +14959,7 @@ proxy-addr@~2.0.5:
forwarded "~0.1.2"
ipaddr.js "1.9.0"
proxy-agent@*, proxy-agent@^3.0.3:
proxy-agent@^3.0.3:
version "3.1.0"
resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-3.1.0.tgz#3cf86ee911c94874de4359f37efd9de25157c113"
integrity sha512-IkbZL4ClW3wwBL/ABFD2zJ8iP84CY0uKMvBPk/OceQe/cEjrxzN1pMHsLwhbzUoRhG9QbSxYC+Z7LBkTiBNvrA==