Skip to content

Commit 8c08fd5

Browse files
authored
feat: add Sentry (#390)
1 parent 186e6eb commit 8c08fd5

File tree

7 files changed

+143
-3
lines changed

7 files changed

+143
-3
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ apiKey=
33
indexName=npm-search
44
bootstrapIndexName=npm-search-bootstrap
55
DOGSTATSD_HOST="localhost"
6+
SENTRY_DSN=

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ See [config.js](./config.js):
231231
- `popularDownloadsRatio`: % of total npm downloads for a package to be considered as popular
232232
how much % of it is needed for a package to be popular - _default 0.2_ This is a bit lower than
233233
the jQuery download range.
234+
- `DOGSTATSD_HOST`: Metrics reporting - _default `localhost`_
235+
- `SENTRY_DSN`: Error reporting - _default `empty`_
234236

235237
## How does it work?
236238

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"license": "MIT",
3030
"dependencies": {
31+
"@sentry/node": "5.6.1",
3132
"algoliasearch": "3.33.0",
3233
"async": "3.1.0",
3334
"babel-cli": "6.26.0",

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as npm from './npm/index.js';
1010
import log from './log.js';
1111
import datadog from './datadog.js';
1212
import * as jsDelivr from './jsDelivr/index.js';
13+
import * as sentry from './utils/sentry.js';
14+
import wait from './utils/wait.js';
1315

1416
log.info('🗿 npm ↔️ Algolia replication starts ⛷ 🐌 🛰');
1517

@@ -324,7 +326,11 @@ async function watch(stateManager, mainIndex) {
324326
});
325327
}
326328

327-
function error(err) {
328-
log.error(err);
329+
async function error(err) {
330+
sentry.report(err);
331+
332+
// Wait for sentry to report the error on their API
333+
await wait(5000);
334+
329335
process.exit(1); // eslint-disable-line no-process-exit
330336
}

src/utils/sentry.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Sentry from '@sentry/node';
2+
3+
import log from '../log.js';
4+
5+
Sentry.init({
6+
dsn: process.env.SENTRY_DSN,
7+
release: `1.0.0`,
8+
environment: 'prod',
9+
serverName: 'npm-search',
10+
});
11+
12+
function report(err, extra = {}) {
13+
log.error(err.message);
14+
if (!process.env.SENTRY_DSN) {
15+
log.error(err);
16+
return;
17+
}
18+
19+
Sentry.withScope(scope => {
20+
scope.setExtras(extra);
21+
Sentry.captureException(err);
22+
});
23+
}
24+
25+
export { report };

src/utils/wait.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default waitTime => {
2+
if (waitTime <= 0) {
3+
return Promise.resolve();
4+
}
5+
6+
return new Promise(resolve => setTimeout(resolve, waitTime));
7+
};

yarn.lock

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,62 @@
824824
dependencies:
825825
any-observable "^0.3.0"
826826

827+
828+
version "5.6.1"
829+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.6.1.tgz#946f064cc500bf4cd2a1bac580192fe440b614c7"
830+
integrity sha512-gK8XfkJIZLsBEQehkr2q2fdHI50B3yo4RXiixSZiNBVIzQ+1z3JcMssDzGwhbY81NHUzHZ7of3oQ4Ab4OGRI/g==
831+
dependencies:
832+
"@sentry/hub" "5.6.1"
833+
"@sentry/minimal" "5.6.1"
834+
"@sentry/types" "5.6.1"
835+
"@sentry/utils" "5.6.1"
836+
tslib "^1.9.3"
837+
838+
839+
version "5.6.1"
840+
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.6.1.tgz#9f355c0abcc92327fbd10b9b939608aa4967bece"
841+
integrity sha512-m+OhkIV5yTAL3R1+XfCwzUQka0UF/xG4py8sEfPXyYIcoOJ2ZTX+1kQJLy8QQJ4RzOBwZA+DzRKP0cgzPJ3+oQ==
842+
dependencies:
843+
"@sentry/types" "5.6.1"
844+
"@sentry/utils" "5.6.1"
845+
tslib "^1.9.3"
846+
847+
848+
version "5.6.1"
849+
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.6.1.tgz#09d92b26de0b24555cd50c3c33ba4c3e566009a1"
850+
integrity sha512-ercCKuBWHog6aS6SsJRuKhJwNdJ2oRQVWT2UAx1zqvsbHT9mSa8ZRjdPHYOtqY3DoXKk/pLUFW/fkmAnpdMqRw==
851+
dependencies:
852+
"@sentry/hub" "5.6.1"
853+
"@sentry/types" "5.6.1"
854+
tslib "^1.9.3"
855+
856+
857+
version "5.6.1"
858+
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-5.6.1.tgz#745adde66e78a605d3edfd3b4108a9e2a6859cc4"
859+
integrity sha512-8gNjFRrTOG3vu2RpWZnUSxNx6Ui2Dthq2VHeVImt7PYtVaSddlYZvt0xl8L/fJC/TvFZEPfX0d8Is9v8yvsgRQ==
860+
dependencies:
861+
"@sentry/core" "5.6.1"
862+
"@sentry/hub" "5.6.1"
863+
"@sentry/types" "5.6.1"
864+
"@sentry/utils" "5.6.1"
865+
cookie "0.3.1"
866+
https-proxy-agent "2.2.1"
867+
lru_map "0.3.3"
868+
tslib "^1.9.3"
869+
870+
871+
version "5.6.1"
872+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.6.1.tgz#5915e1ee4b7a678da3ac260c356b1cb91139a299"
873+
integrity sha512-Kub8TETefHpdhvtnDj3kKfhCj0u/xn3Zi2zIC7PB11NJHvvPXENx97tciz4roJGp7cLRCJsFqCg4tHXniqDSnQ==
874+
875+
876+
version "5.6.1"
877+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.6.1.tgz#69d9e151e50415bc91f2428e3bcca8beb9bc2815"
878+
integrity sha512-rfgha+UsHW816GqlSRPlniKqAZylOmQWML2JsujoUP03nPu80zdN43DK9Poy/d9OxBxv0gd5K2n+bFdM2kqLQQ==
879+
dependencies:
880+
"@sentry/types" "5.6.1"
881+
tslib "^1.9.3"
882+
827883
"@sindresorhus/is@^0.14.0":
828884
version "0.14.0"
829885
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
@@ -991,6 +1047,13 @@ acorn@^6.0.7:
9911047
version "6.1.0"
9921048
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.1.0.tgz#b0a3be31752c97a0f7013c5f4903b71a05db6818"
9931049

1050+
agent-base@^4.1.0:
1051+
version "4.3.0"
1052+
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
1053+
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
1054+
dependencies:
1055+
es6-promisify "^5.0.0"
1056+
9941057
agentkeepalive@^2.2.0:
9951058
version "2.2.0"
9961059
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef"
@@ -2436,6 +2499,11 @@ convert-source-map@^1.5.0:
24362499
version "1.5.0"
24372500
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.0.tgz#9acd70851c6d5dfdd93d9282e5edf94a03ff46b5"
24382501

2502+
2503+
version "0.3.1"
2504+
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
2505+
integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=
2506+
24392507
copy-descriptor@^0.1.0:
24402508
version "0.1.1"
24412509
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
@@ -2587,7 +2655,7 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
25872655
dependencies:
25882656
ms "2.0.0"
25892657

2590-
debug@^3.2.6:
2658+
debug@^3.1.0, debug@^3.2.6:
25912659
version "3.2.6"
25922660
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
25932661
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
@@ -2940,10 +3008,22 @@ es-to-primitive@^1.2.0:
29403008
is-date-object "^1.0.1"
29413009
is-symbol "^1.0.2"
29423010

3011+
es6-promise@^4.0.3:
3012+
version "4.2.8"
3013+
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
3014+
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==
3015+
29433016
es6-promise@^4.1.0:
29443017
version "4.1.1"
29453018
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.1.1.tgz#8811e90915d9a0dba36274f0b242dbda78f9c92a"
29463019

3020+
es6-promisify@^5.0.0:
3021+
version "5.0.0"
3022+
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
3023+
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
3024+
dependencies:
3025+
es6-promise "^4.0.3"
3026+
29473027
29483028
version "1.0.3"
29493029
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
@@ -3975,6 +4055,14 @@ https-browserify@^1.0.0:
39754055
version "1.0.0"
39764056
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
39774057

4058+
4059+
version "2.2.1"
4060+
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
4061+
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
4062+
dependencies:
4063+
agent-base "^4.1.0"
4064+
debug "^3.1.0"
4065+
39784066
39794067
version "3.0.2"
39804068
resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.2.tgz#e78fd2ae16edca59fc88e56aeb8d70acdcc1c082"
@@ -5301,6 +5389,11 @@ lru-cache@^4.0.1:
53015389
pseudomap "^1.0.2"
53025390
yallist "^2.1.2"
53035391

5392+
5393+
version "0.3.3"
5394+
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
5395+
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
5396+
53045397
make-dir@^2.1.0:
53055398
version "2.1.0"
53065399
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
@@ -7814,6 +7907,11 @@ tslib@^1.9.0:
78147907
version "1.9.1"
78157908
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7"
78167909

7910+
tslib@^1.9.3:
7911+
version "1.10.0"
7912+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
7913+
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
7914+
78177915
78187916
version "0.0.0"
78197917
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)