From b9f846c9f64f7a555f46c83d0cd14730db0a7c22 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 6 Mar 2018 13:45:51 -0500 Subject: [PATCH 01/16] upload sourcemaps --- src/index.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4a78eb1..1be1f45 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,8 @@ const _ = require("lodash") , SemVer = require("semver") , uuid = require("uuid/v4") , request = require("superagent") - , GitRev = require("./git-rev"); + , GitRev = require("./git-rev") + , glob = require("glob-all"); /** * Serverless Plugin forward Lambda exceptions to Sentry (https://sentry.io) @@ -25,6 +26,11 @@ class Sentry { .then(this.setRelease) .then(this.instrumentFunctions), + "before:package:createDeploymentArtifacts": () => BbPromise.bind(this) + .then(this.createSentryRelease) + .then(this.deploySentryRelease) + .then(this.deploySentrySourceMaps), + "before:deploy:deploy": () => BbPromise.bind(this) .then(this.validate), @@ -288,6 +294,61 @@ class Sentry { }); } + deploySentrySourceMaps() { + if (!this.sentry.authToken || !this.sentry.release) { + // Nothing to do + return BbPromise.resolve(); + } + + const organization = this.sentry.organization; + const release = this.sentry.release; + const buildDirectory = this._serverless.config.servicePath; + this._serverless.cli.log( + `Sentry: Uploading source maps for "${release.version}" from directory ${buildDirectory}...` + ); + + const upload = filepath => BbPromise.fromCallback(cb => { + this._serverless.cli.log( + `Sentry: Uploading file ${filepath} to sentry...` + ); + return request.post( + `https://sentry.io/api/0/organizations/${organization}/releases/${encodeURIComponent( + release.version + )}/files/` + ).set("Authorization", `Bearer ${this.sentry.authToken}`) + .attach( + "file", + filepath + ) + .end( (error, result) => { + if(result && result.status === 409) { + return cb(null, result); + } + + if(error) { + return cb(error); + } + + return cb(null, result); + }); + }); + + const types = ["js", "js.map"]; + const files = glob.sync(types.map( t => `${buildDirectory}/**/*.${t}`).concat(types.map( t => `${buildDirectory}/../node_modules/**/*.${t}`))); const uploads = files.map( f => () => upload(f)); + return BbPromise.map(uploads, u => u(), { concurrency: 10 }).catch(err => { + if (err && err.response && err.responsetext) { + this._serverless.cli.log( + `Sentry: Received error response from Sentry:\n${err.response.text}` + ); + } + return BbPromise.reject( + new this._serverless.classes.Error( + "Sentry: Error uploading source map - " + err.stack + ) + ); + }); + } + getRandomVersion() { return _.replace(uuid(), /-/g, ""); } From 54de6418fad42f6fbb547771ab6892aae8190d78 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 15:27:07 -0400 Subject: [PATCH 02/16] upload sourcemaps --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 1be1f45..0cdef8a 100644 --- a/src/index.js +++ b/src/index.js @@ -295,7 +295,7 @@ class Sentry { } deploySentrySourceMaps() { - if (!this.sentry.authToken || !this.sentry.release) { + if (!this.sentry.authToken || !this.sentry.release || !this.sentry.uploadSourcemaps) { // Nothing to do return BbPromise.resolve(); } @@ -318,6 +318,7 @@ class Sentry { ).set("Authorization", `Bearer ${this.sentry.authToken}`) .attach( "file", + filepath, filepath ) .end( (error, result) => { @@ -333,8 +334,8 @@ class Sentry { }); }); - const types = ["js", "js.map"]; - const files = glob.sync(types.map( t => `${buildDirectory}/**/*.${t}`).concat(types.map( t => `${buildDirectory}/../node_modules/**/*.${t}`))); const uploads = files.map( f => () => upload(f)); + const types = ["js", "js.map", "ts"]; + const files = glob.sync(types.map( t => `${buildDirectory}/../**/*.${t}`)); const uploads = files.map( f => () => upload(f)); return BbPromise.map(uploads, u => u(), { concurrency: 10 }).catch(err => { if (err && err.response && err.responsetext) { this._serverless.cli.log( From db4050776d655470b9077427c2eeb5783958b2ec Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 15:44:28 -0400 Subject: [PATCH 03/16] add glob-all --- package-lock.json | 44 +++++++++++++++++++++++++++++--------------- package.json | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index e10d69b..80712af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -128,8 +128,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "bluebird": { "version": "3.5.1", @@ -140,7 +139,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -250,8 +248,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "cookiejar": { "version": "2.1.2", @@ -556,8 +553,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "function-bind": { "version": "1.1.1", @@ -575,7 +571,6 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -585,6 +580,15 @@ "path-is-absolute": "^1.0.0" } }, + "glob-all": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/glob-all/-/glob-all-3.1.0.tgz", + "integrity": "sha1-iRPd+17hrHgSZWJBsD1SF8ZLAqs=", + "requires": { + "glob": "^7.0.5", + "yargs": "~1.2.6" + } + }, "globals": { "version": "11.7.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz", @@ -666,7 +670,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -854,7 +857,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -913,7 +915,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -950,8 +951,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", @@ -1318,8 +1318,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "0.2.1", @@ -1329,6 +1328,21 @@ "requires": { "mkdirp": "^0.5.1" } + }, + "yargs": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-1.2.6.tgz", + "integrity": "sha1-nHtKgv1dWVsr8Xq23MQxNUMv40s=", + "requires": { + "minimist": "^0.1.0" + }, + "dependencies": { + "minimist": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.1.0.tgz", + "integrity": "sha1-md9lelJXTCHJBXSX33QnkLK0wN4=" + } + } } } } diff --git a/package.json b/package.json index 3e39cb5..1363c7b 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "bluebird": "^3.5.1", + "glob-all": "^3.1.0", "lodash": "^4.17.10", "semver": "^5.5.0", "superagent": "^3.8.3", From 7c2618ba49f4012cee5c843c72e131bf3afd664d Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 15:47:41 -0400 Subject: [PATCH 04/16] gitlab releases --- src/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0cdef8a..e81e1e3 100644 --- a/src/index.js +++ b/src/index.js @@ -162,9 +162,23 @@ class Sentry { _resolveGitRefs(gitRev) { return BbPromise.join( - gitRev.origin().then(str => str.match(/[:/]([^/]+\/[^/]+?)(?:\.git)?$/i)[1]).catch(_.noop), + gitRev.origin(), gitRev.long() ) + .spread((origin, commit) => { + let repository = null; + try { + repository = origin.match(/[:/]([^/]+\/[^/]+?)(?:\.git)?$/i)[1]; + if(_.includes(origin, "gitlab")) { + // gitlab uses spaces around the slashes in the repository name + repository = repository.replace(/\//g, " / "); + } + } + catch (err) { + // ignore + } + return BbPromise.join(repository, commit); + }) .spread((repository, commit) => { _.forEach(_.get(this.sentry, "release.refs", []), ref => { if (ref && ref.repository === "git") { From e008babf1d9fef8a8669503129465641fcb4af40 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 16:16:35 -0400 Subject: [PATCH 05/16] upload built artifacts --- src/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index e81e1e3..a2f3694 100644 --- a/src/index.js +++ b/src/index.js @@ -28,9 +28,12 @@ class Sentry { "before:package:createDeploymentArtifacts": () => BbPromise.bind(this) .then(this.createSentryRelease) - .then(this.deploySentryRelease) + .then(this.deploySentryRelease), + + "after:package:createDeploymentArtifacts": () => BbPromise.bind(this) .then(this.deploySentrySourceMaps), + "before:deploy:deploy": () => BbPromise.bind(this) .then(this.validate), @@ -318,7 +321,7 @@ class Sentry { const release = this.sentry.release; const buildDirectory = this._serverless.config.servicePath; this._serverless.cli.log( - `Sentry: Uploading source maps for "${release.version}" from directory ${buildDirectory}...` + `Sentry: Uploading source maps for "${release.version}" from directory "${buildDirectory}"...` ); const upload = filepath => BbPromise.fromCallback(cb => { @@ -349,7 +352,15 @@ class Sentry { }); const types = ["js", "js.map", "ts"]; - const files = glob.sync(types.map( t => `${buildDirectory}/../**/*.${t}`)); const uploads = files.map( f => () => upload(f)); + const globs = types + .map( t => `${buildDirectory}/**/*.${t}`) + .concat(types.map( t => `${buildDirectory}/../node_modules/**/*.${t}`)); + + this._serverless.cli.log( + `Sentry: Uploading source maps for globs ${globs}...` + ); + const files = glob.sync(globs); + const uploads = files.map( f => () => upload(f)); return BbPromise.map(uploads, u => u(), { concurrency: 10 }).catch(err => { if (err && err.response && err.responsetext) { this._serverless.cli.log( From 3fe15c783ede1b295805bb209f350dc719e00b2f Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 16:23:44 -0400 Subject: [PATCH 06/16] upload ts sources --- src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index a2f3694..bdce0fa 100644 --- a/src/index.js +++ b/src/index.js @@ -353,8 +353,7 @@ class Sentry { const types = ["js", "js.map", "ts"]; const globs = types - .map( t => `${buildDirectory}/**/*.${t}`) - .concat(types.map( t => `${buildDirectory}/../node_modules/**/*.${t}`)); + .map( t => `${buildDirectory}/../**/*.${t}`); this._serverless.cli.log( `Sentry: Uploading source maps for globs ${globs}...` From 211bd3386a8f17ed2ab441bc08233344f278e727 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 16:29:17 -0400 Subject: [PATCH 07/16] exclude type definitions --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index bdce0fa..a9be191 100644 --- a/src/index.js +++ b/src/index.js @@ -353,7 +353,8 @@ class Sentry { const types = ["js", "js.map", "ts"]; const globs = types - .map( t => `${buildDirectory}/../**/*.${t}`); + .map( t => `${buildDirectory}/../**/*.${t}`) + .push(`!${buildDirectory}/../**/*.d.ts`); this._serverless.cli.log( `Sentry: Uploading source maps for globs ${globs}...` From 33795056a455e77d26b53c61717caf90125013be Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 16:39:49 -0400 Subject: [PATCH 08/16] upload retries --- src/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index a9be191..46ca52e 100644 --- a/src/index.js +++ b/src/index.js @@ -323,7 +323,9 @@ class Sentry { this._serverless.cli.log( `Sentry: Uploading source maps for "${release.version}" from directory "${buildDirectory}"...` ); - + + const retryCount = {}; + const retries = 3; const upload = filepath => BbPromise.fromCallback(cb => { this._serverless.cli.log( `Sentry: Uploading file ${filepath} to sentry...` @@ -342,9 +344,18 @@ class Sentry { if(result && result.status === 409) { return cb(null, result); } - + if(error) { - return cb(error); + if(!retryCount[filepath]) { + retryCount[filepath] = 0; + } + + retryCount[filepath] += 1; + if(retryCount[filepath] > retries) { + return cb(error); + } + + return upload(filepath); } return cb(null, result); From 1738e41dba09da926df8a3dec57c829aaf2ce2be Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 16:50:24 -0400 Subject: [PATCH 09/16] throttle requests --- package-lock.json | 5 +++++ package.json | 1 + src/index.js | 34 +++++++++++++++++++--------------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80712af..4f1053e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1225,6 +1225,11 @@ "readable-stream": "^2.3.5" } }, + "superagent-throttle": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/superagent-throttle/-/superagent-throttle-1.0.1.tgz", + "integrity": "sha512-m5Ngf0S5QoA84zgwVqVnVA34u9uvo8uM+QEF9B7eNI5FDaSoSoUwQsx7V1GmLXgYLkolhIiucFDVJXF9z49hgQ==" + }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", diff --git a/package.json b/package.json index 1363c7b..9c70338 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "lodash": "^4.17.10", "semver": "^5.5.0", "superagent": "^3.8.3", + "superagent-throttle": "^1.0.1", "uuid": "^3.3.2" }, "peerDependencies": { diff --git a/src/index.js b/src/index.js index 46ca52e..fd4e758 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,8 @@ const _ = require("lodash") , uuid = require("uuid/v4") , request = require("superagent") , GitRev = require("./git-rev") - , glob = require("glob-all"); + , glob = require("glob-all") + , Throttle = require('superagent-throttle'); /** * Serverless Plugin forward Lambda exceptions to Sentry (https://sentry.io) @@ -323,9 +324,14 @@ class Sentry { this._serverless.cli.log( `Sentry: Uploading source maps for "${release.version}" from directory "${buildDirectory}"...` ); - - const retryCount = {}; - const retries = 3; + + const throttle = new Throttle({ + active: true, // set false to pause queue + rate: 10, // how many requests can be sent every `ratePer` + ratePer: 1000, // number of ms in which `rate` requests may be sent + concurrent: 2 // how many requests can be sent concurrently + }); + const upload = filepath => BbPromise.fromCallback(cb => { this._serverless.cli.log( `Sentry: Uploading file ${filepath} to sentry...` @@ -340,22 +346,20 @@ class Sentry { filepath, filepath ) + .use(throttle.plugin()) + .retry(3, () => { + this._serverless.cli.log( + `Sentry: Uploading source map failed for ${filepath}...` + ); + return true; + }) .end( (error, result) => { if(result && result.status === 409) { return cb(null, result); } if(error) { - if(!retryCount[filepath]) { - retryCount[filepath] = 0; - } - - retryCount[filepath] += 1; - if(retryCount[filepath] > retries) { - return cb(error); - } - - return upload(filepath); + return cb(error); } return cb(null, result); @@ -372,7 +376,7 @@ class Sentry { ); const files = glob.sync(globs); const uploads = files.map( f => () => upload(f)); - return BbPromise.map(uploads, u => u(), { concurrency: 10 }).catch(err => { + return BbPromise.map(uploads, u => u()).catch(err => { if (err && err.response && err.responsetext) { this._serverless.cli.log( `Sentry: Received error response from Sentry:\n${err.response.text}` From e2b5ab3b5aa47ab6c1301719682977a55debfc6a Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 22 Apr 2019 17:45:22 -0400 Subject: [PATCH 10/16] upload speed --- src/index.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index fd4e758..8e421d0 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,7 @@ const _ = require("lodash") , request = require("superagent") , GitRev = require("./git-rev") , glob = require("glob-all") + , util = require("util") , Throttle = require('superagent-throttle'); /** @@ -327,31 +328,39 @@ class Sentry { const throttle = new Throttle({ active: true, // set false to pause queue - rate: 10, // how many requests can be sent every `ratePer` + rate: 100, // how many requests can be sent every `ratePer` ratePer: 1000, // number of ms in which `rate` requests may be sent - concurrent: 2 // how many requests can be sent concurrently + concurrent: 10 // how many requests can be sent concurrently + }).on("sent", (request) => { + this._serverless.cli.log( + `Sentry: Uploading file ${request.filepath} to sentry...` + ); }); const upload = filepath => BbPromise.fromCallback(cb => { - this._serverless.cli.log( - `Sentry: Uploading file ${filepath} to sentry...` - ); + return request.post( `https://sentry.io/api/0/organizations/${organization}/releases/${encodeURIComponent( release.version )}/files/` - ).set("Authorization", `Bearer ${this.sentry.authToken}`) + ) + .set("Authorization", `Bearer ${this.sentry.authToken}`) .attach( "file", filepath, filepath ) + .use((req) => { + req.filepath = filepath; + return req; + }) .use(throttle.plugin()) - .retry(3, () => { - this._serverless.cli.log( - `Sentry: Uploading source map failed for ${filepath}...` - ); - return true; + .retry(3, (error) => { + if(error) { + this._serverless.cli.log( + `Sentry: Uploading file ${filepath} to sentry failed with error ${error}...` + ); + } }) .end( (error, result) => { if(result && result.status === 409) { @@ -369,7 +378,7 @@ class Sentry { const types = ["js", "js.map", "ts"]; const globs = types .map( t => `${buildDirectory}/../**/*.${t}`) - .push(`!${buildDirectory}/../**/*.d.ts`); + .concat(`!${buildDirectory}/../**/*.d.ts`); this._serverless.cli.log( `Sentry: Uploading source maps for globs ${globs}...` From 7065ce0bf9aca29c03049aea70b0821480a4fc48 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 08:52:06 -0400 Subject: [PATCH 11/16] increase upload rate --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 8e421d0..f0a9bba 100644 --- a/src/index.js +++ b/src/index.js @@ -328,9 +328,9 @@ class Sentry { const throttle = new Throttle({ active: true, // set false to pause queue - rate: 100, // how many requests can be sent every `ratePer` + rate: 1000, // how many requests can be sent every `ratePer` ratePer: 1000, // number of ms in which `rate` requests may be sent - concurrent: 10 // how many requests can be sent concurrently + concurrent: 100 // how many requests can be sent concurrently }).on("sent", (request) => { this._serverless.cli.log( `Sentry: Uploading file ${request.filepath} to sentry...` From 941bc695a5d3870bd6678114031140b6a64135c4 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 10:12:42 -0400 Subject: [PATCH 12/16] reduce rate limit --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f0a9bba..37920c2 100644 --- a/src/index.js +++ b/src/index.js @@ -328,7 +328,7 @@ class Sentry { const throttle = new Throttle({ active: true, // set false to pause queue - rate: 1000, // how many requests can be sent every `ratePer` + rate: 100, // how many requests can be sent every `ratePer` ratePer: 1000, // number of ms in which `rate` requests may be sent concurrent: 100 // how many requests can be sent concurrently }).on("sent", (request) => { From ca8db0d102e5b048a8b785294b112402ef828d94 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 12:24:22 -0400 Subject: [PATCH 13/16] custom sourcemap paths --- src/index.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 37920c2..bba848d 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,8 @@ const _ = require("lodash") , request = require("superagent") , GitRev = require("./git-rev") , glob = require("glob-all") - , util = require("util") - , Throttle = require('superagent-throttle'); + , path = require("path") + , Throttle = require("superagent-throttle"); /** * Serverless Plugin forward Lambda exceptions to Sentry (https://sentry.io) @@ -321,7 +321,7 @@ class Sentry { const organization = this.sentry.organization; const release = this.sentry.release; - const buildDirectory = this._serverless.config.servicePath; + const buildDirectory = path.join(this._serverless.config.servicePath, "../"); this._serverless.cli.log( `Sentry: Uploading source maps for "${release.version}" from directory "${buildDirectory}"...` ); @@ -333,12 +333,20 @@ class Sentry { concurrent: 100 // how many requests can be sent concurrently }).on("sent", (request) => { this._serverless.cli.log( - `Sentry: Uploading file ${request.filepath} to sentry...` + `Sentry: Uploading file ${request.filename} to sentry...` ); }); const upload = filepath => BbPromise.fromCallback(cb => { + let filename = null; + if(_.includes(filepath, "node_modules")) { + filename = `/var/task/node_modues/${filepath.split("node_modules/")[1]}`; + } + else { + filename = `/var/${filepath.split(buildDirectory)[1]}`; + } + return request.post( `https://sentry.io/api/0/organizations/${organization}/releases/${encodeURIComponent( release.version @@ -348,10 +356,11 @@ class Sentry { .attach( "file", filepath, - filepath + filename ) .use((req) => { - req.filepath = filepath; + req.filepath = filepath; + req.filename = filename; return req; }) .use(throttle.plugin()) @@ -377,8 +386,8 @@ class Sentry { const types = ["js", "js.map", "ts"]; const globs = types - .map( t => `${buildDirectory}/../**/*.${t}`) - .concat(`!${buildDirectory}/../**/*.d.ts`); + .map( t => `${buildDirectory}/**/*.${t}`) + .concat(`!${buildDirectory}/**/*.d.ts`); this._serverless.cli.log( `Sentry: Uploading source maps for globs ${globs}...` From 26c0c29135ae6a30ed0462e50781543979c2d8c9 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 12:47:15 -0400 Subject: [PATCH 14/16] slow down --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index bba848d..f5a90b2 100644 --- a/src/index.js +++ b/src/index.js @@ -328,9 +328,9 @@ class Sentry { const throttle = new Throttle({ active: true, // set false to pause queue - rate: 100, // how many requests can be sent every `ratePer` + rate: 10, // how many requests can be sent every `ratePer` ratePer: 1000, // number of ms in which `rate` requests may be sent - concurrent: 100 // how many requests can be sent concurrently + concurrent: 2 // how many requests can be sent concurrently }).on("sent", (request) => { this._serverless.cli.log( `Sentry: Uploading file ${request.filename} to sentry...` @@ -367,7 +367,7 @@ class Sentry { .retry(3, (error) => { if(error) { this._serverless.cli.log( - `Sentry: Uploading file ${filepath} to sentry failed with error ${error}...` + `Sentry: Uploading file ${filename} to sentry failed with error ${error}...` ); } }) From 466392c0b5147d9c3ff4ff0b941bbe924e3148ce Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 13:09:58 -0400 Subject: [PATCH 15/16] fix relative paths --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index f5a90b2..b661e63 100644 --- a/src/index.js +++ b/src/index.js @@ -339,12 +339,12 @@ class Sentry { const upload = filepath => BbPromise.fromCallback(cb => { - let filename = null; - if(_.includes(filepath, "node_modules")) { - filename = `/var/task/node_modues/${filepath.split("node_modules/")[1]}`; + let filename = filepath.split(buildDirectory)[1]; + if(filename.startsWith("node_modules")) { + filename = `/var/task/${filename}`; } else { - filename = `/var/${filepath.split(buildDirectory)[1]}`; + filename = `/var/${filename}`; } return request.post( @@ -387,6 +387,7 @@ class Sentry { const types = ["js", "js.map", "ts"]; const globs = types .map( t => `${buildDirectory}/**/*.${t}`) + .concat(`!${buildDirectory}/node_modules`) .concat(`!${buildDirectory}/**/*.d.ts`); this._serverless.cli.log( From 494e2814c5ec07eb513ccf09689c0cb07a4599ac Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Tue, 23 Apr 2019 14:15:49 -0400 Subject: [PATCH 16/16] is retry causing issues? --- src/index.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index b661e63..52ac0df 100644 --- a/src/index.js +++ b/src/index.js @@ -328,9 +328,9 @@ class Sentry { const throttle = new Throttle({ active: true, // set false to pause queue - rate: 10, // how many requests can be sent every `ratePer` + rate: 20, // how many requests can be sent every `ratePer` ratePer: 1000, // number of ms in which `rate` requests may be sent - concurrent: 2 // how many requests can be sent concurrently + concurrent: 5 // how many requests can be sent concurrently }).on("sent", (request) => { this._serverless.cli.log( `Sentry: Uploading file ${request.filename} to sentry...` @@ -364,13 +364,6 @@ class Sentry { return req; }) .use(throttle.plugin()) - .retry(3, (error) => { - if(error) { - this._serverless.cli.log( - `Sentry: Uploading file ${filename} to sentry failed with error ${error}...` - ); - } - }) .end( (error, result) => { if(result && result.status === 409) { return cb(null, result);