|
@@ -1,8 +1,12 @@
|
|
|
/* eslint-env node */
|
|
|
/* eslint import/no-nodejs-modules:0 */
|
|
|
-const crypto = require('crypto');
|
|
|
-const https = require('https');
|
|
|
-const os = require('os');
|
|
|
+
|
|
|
+import crypto from 'crypto';
|
|
|
+import https from 'https';
|
|
|
+import os from 'os';
|
|
|
+
|
|
|
+import type Sentry from '@sentry/node';
|
|
|
+import webpack from 'webpack';
|
|
|
|
|
|
const {
|
|
|
NODE_ENV,
|
|
@@ -11,17 +15,22 @@ const {
|
|
|
GITHUB_SHA,
|
|
|
GITHUB_REF,
|
|
|
} = process.env;
|
|
|
+
|
|
|
const IS_CI = !!GITHUB_SHA;
|
|
|
|
|
|
const PLUGIN_NAME = 'SentryInstrumentation';
|
|
|
const GB_BYTE = 1073741824;
|
|
|
|
|
|
-const createSignature = function (secret, payload) {
|
|
|
+const createSignature = function (secret: string, payload: string) {
|
|
|
const hmac = crypto.createHmac('sha1', secret);
|
|
|
return `sha1=${hmac.update(payload).digest('hex')}`;
|
|
|
};
|
|
|
|
|
|
class SentryInstrumentation {
|
|
|
+ initialBuild: boolean = false;
|
|
|
+
|
|
|
+ Sentry?: typeof Sentry;
|
|
|
+
|
|
|
constructor() {
|
|
|
// Only run if SENTRY_INSTRUMENTATION` is set or when in ci,
|
|
|
// only in the javascript suite that runs webpack
|
|
@@ -29,40 +38,41 @@ class SentryInstrumentation {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.initialBuild = false;
|
|
|
- this.Sentry = require('@sentry/node');
|
|
|
+ const sentry = require('@sentry/node');
|
|
|
require('@sentry/tracing'); // This is required to patch Sentry
|
|
|
|
|
|
- this.Sentry.init({
|
|
|
+ sentry.init({
|
|
|
dsn: 'https://3d282d186d924374800aa47006227ce9@sentry.io/2053674',
|
|
|
environment: IS_CI ? 'ci' : 'local',
|
|
|
tracesSampleRate: 1.0,
|
|
|
});
|
|
|
|
|
|
if (IS_CI) {
|
|
|
- this.Sentry.setTag('branch', GITHUB_REF);
|
|
|
+ sentry.setTag('branch', GITHUB_REF);
|
|
|
}
|
|
|
|
|
|
const cpus = os.cpus();
|
|
|
- this.Sentry.setTag('platform', os.platform());
|
|
|
- this.Sentry.setTag('arch', os.arch());
|
|
|
- this.Sentry.setTag(
|
|
|
+ sentry.setTag('platform', os.platform());
|
|
|
+ sentry.setTag('arch', os.arch());
|
|
|
+ sentry.setTag(
|
|
|
'cpu',
|
|
|
cpus && cpus.length ? `${cpus[0].model} (cores: ${cpus.length})}` : 'N/A'
|
|
|
);
|
|
|
+
|
|
|
+ this.Sentry = sentry;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Measures the file sizes of assets emitted from the entrypoints
|
|
|
*/
|
|
|
- measureAssetSizes(compilation) {
|
|
|
+ measureAssetSizes(compilation: webpack.Compilation) {
|
|
|
if (!SENTRY_WEBPACK_WEBHOOK_SECRET) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
[...compilation.entrypoints].forEach(([entrypointName, entry]) =>
|
|
|
entry.chunks.forEach(chunk =>
|
|
|
- chunk.files
|
|
|
+ Array.from(chunk.files)
|
|
|
.filter(assetName => !assetName.endsWith('.map'))
|
|
|
.forEach(assetName => {
|
|
|
const asset = compilation.assets[assetName];
|
|
@@ -96,7 +106,7 @@ class SentryInstrumentation {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- measureBuildTime(startTime, endTime) {
|
|
|
+ measureBuildTime(startTime: number, endTime: number) {
|
|
|
if (!this.Sentry) {
|
|
|
return;
|
|
|
}
|
|
@@ -127,7 +137,7 @@ class SentryInstrumentation {
|
|
|
transaction.finish();
|
|
|
}
|
|
|
|
|
|
- apply(compiler) {
|
|
|
+ apply(compiler: webpack.Compiler) {
|
|
|
compiler.hooks.done.tapAsync(
|
|
|
PLUGIN_NAME,
|
|
|
async ({compilation, startTime, endTime}, done) => {
|
|
@@ -149,4 +159,5 @@ class SentryInstrumentation {
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
-module.exports = SentryInstrumentation;
|
|
|
+
|
|
|
+export default SentryInstrumentation;
|