Skip to content

Commit 4e2fee7

Browse files
jpreynatschneidmaster
authored andcommitted
Add uploadFilesConcurrency option (defaults to Infinity) to throttle source files upload (#67)
* Add es6-promise-pool * Limit concurrent files upload requests to 10 * Make uploadFilesConcurrency an option that defaults to Infinity
1 parent 9b8c7b3 commit 4e2fee7

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var config = {
3838
organization: 'your-organization-name',
3939
project: 'your-project-name',
4040
apiKey: process.env.SENTRY_API_KEY,
41-
41+
4242
// Release version name/hash is required
4343
release: process.env.GIT_SHA
4444
})
@@ -98,7 +98,7 @@ var config = {
9898
]
9999
}
100100
```
101-
101+
102102
- `releaseBody`: Object or function that returns the body that will be sent to Sentry. Defaults to sending the version and projects (which is sufficient to create a basic new release in Sentry).
103103
- The function is given two arguments: `version` and `projects`. `version` is the result of the `release` object (string or function output); `projects` is the `project` configuration parameter (converted to an array if a single string is provided).
104104
- The most common use case for overriding this field is Sentry's [release commits](https://docs.sentry.io/learn/releases/#releases-are-better-with-commits) feature. To use this, define `releaseBody` per the example below (providing the most recent commit hash through whatever means works best for your build setup). See the Sentry documentation for more details and options.
@@ -108,7 +108,7 @@ var config = {
108108
plugins: [
109109
new SentryPlugin({
110110
releaseBody: function(version, projects) {
111-
return {
111+
return {
112112
version,
113113
projects,
114114
refs: [{
@@ -136,6 +136,8 @@ var config = {
136136
- `uploadFileRequestOptions`: Object of options or function returning object of options passed through to the underlying `request` call on file uploading; see the [request library documentation](https://github.com/request/request#requestoptions-callback) for available options.
137137
- If a function is provided, it is given one argument: req, an object of options (including url, auth, and body) that the plugin is sending to the underlying request call. (This is useful if you want to configure the request dynamically based on request data such as the filename.)
138138

139+
- `uploadFilesConcurrency`: Number of maximum concurrent uploads of source files to the Sentry API. Use this when the number of source files to upload to Sentry is high and you encounter the `RequestError: Error: getaddrinfo ENOTFOUND sentry.io sentry.io:443` error.
140+
139141
### What is a `release`?
140142

141143
A [release](https://docs.sentry.io/learn/releases/) is a concept that Sentry uses to attach source maps to a known version of your code. The plugin creates one for you, but you need to provide a "name" for a particular version of your code, which is just a string. Sentry can then use the release to record that an error was found in a specific known version of your code. Releases are also used to "version" your source maps -- source maps are uploaded to a specific release, and when a raw JavaScript error is reported, the release reported with the error is used to locate and apply the correct source maps.
@@ -148,7 +150,7 @@ A git commit hash is very useful for releases - it is a string that defines a pa
148150
new SentryPlugin({
149151
// ...
150152
release: function() {
151-
// Note: this is just an example, it depends on your deployment pipeline
153+
// Note: this is just an example, it depends on your deployment pipeline
152154
return process.env.SOURCE_VERSION;
153155
}
154156
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
]
3737
},
3838
"dependencies": {
39+
"es6-promise-pool": "^2.5.0",
3940
"request": "^2.85.0",
4041
"request-promise": "^4.2.2"
4142
},

src/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import request from 'request-promise'
22
import fs from 'fs'
3+
import PromisePool from 'es6-promise-pool'
34

45
const BASE_SENTRY_URL = 'https://sentry.io/api/0'
56

67
const DEFAULT_INCLUDE = /\.js$|\.map$/
78
const DEFAULT_TRANSFORM = filename => `~/${filename}`
89
const DEFAULT_DELETE_REGEX = /\.map$/
910
const DEFAULT_BODY_TRANSFORM = (version, projects) => ({ version, projects })
11+
const DEFAULT_UPLOAD_FILES_CONCURRENCY = Infinity
1012

1113
module.exports = class SentryPlugin {
1214
constructor(options) {
@@ -71,6 +73,8 @@ module.exports = class SentryPlugin {
7173

7274
this.deleteAfterCompile = options.deleteAfterCompile
7375
this.deleteRegex = options.deleteRegex || DEFAULT_DELETE_REGEX
76+
this.uploadFilesConcurrency =
77+
options.uploadFilesConcurrency || DEFAULT_UPLOAD_FILES_CONCURRENCY
7478
}
7579

7680
apply(compiler) {
@@ -191,7 +195,15 @@ module.exports = class SentryPlugin {
191195
}
192196

193197
uploadFiles(files) {
194-
return Promise.all(files.map(this.uploadFile.bind(this)))
198+
const pool = new PromisePool(() => {
199+
const file = files.pop()
200+
if (!file) {
201+
return null
202+
}
203+
204+
return this.uploadFile(file)
205+
}, this.uploadFilesConcurrency)
206+
return pool.start()
195207
}
196208

197209
uploadFile({ path, name }) {

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,10 @@ es-to-primitive@^1.1.1:
16191619
is-date-object "^1.0.1"
16201620
is-symbol "^1.0.1"
16211621

1622+
es6-promise-pool@^2.5.0:
1623+
version "2.5.0"
1624+
resolved "https://registry.yarnpkg.com/es6-promise-pool/-/es6-promise-pool-2.5.0.tgz#147c612b36b47f105027f9d2bf54a598a99d9ccb"
1625+
16221626
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
16231627
version "1.0.5"
16241628
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

0 commit comments

Comments
 (0)