Upgrade to new Sentry SDKs; fix error reporting detail (#3764)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
'use strict'
|
||||
const Raven = require('raven')
|
||||
const throttle = require('lodash.throttle')
|
||||
const Sentry = require('@sentry/node')
|
||||
|
||||
const listeners = []
|
||||
|
||||
@@ -30,22 +29,11 @@ module.exports = function log(...msg) {
|
||||
console.log(d, ...msg)
|
||||
}
|
||||
|
||||
const throttledConsoleError = throttle(console.error, 10000, {
|
||||
trailing: false,
|
||||
})
|
||||
|
||||
module.exports.error = function error(...msg) {
|
||||
module.exports.error = function error(err) {
|
||||
const d = date()
|
||||
listeners.forEach(f => f(d, ...msg))
|
||||
Raven.captureException(msg, sendErr => {
|
||||
if (sendErr) {
|
||||
throttledConsoleError(
|
||||
'Failed to send captured exception to Sentry',
|
||||
sendErr.message
|
||||
)
|
||||
}
|
||||
})
|
||||
console.error(d, ...msg)
|
||||
listeners.forEach(f => f(d, err))
|
||||
Sentry.captureException(err)
|
||||
console.error(d, err)
|
||||
}
|
||||
|
||||
module.exports.addListener = function addListener(func) {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
'use strict'
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
const sinon = require('sinon')
|
||||
const sinonChai = require('sinon-chai')
|
||||
const Raven = require('raven')
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
function requireUncached(module) {
|
||||
delete require.cache[require.resolve(module)]
|
||||
return require(module)
|
||||
}
|
||||
|
||||
describe('log', function() {
|
||||
describe('error', function() {
|
||||
before(function() {
|
||||
this.clock = sinon.useFakeTimers()
|
||||
sinon.stub(Raven, 'captureException').callsFake((e, callback) => {
|
||||
callback(new Error(`Cannot send message "${e}" to Sentry.`))
|
||||
})
|
||||
// we have to create a spy before requiring 'error' function
|
||||
sinon.spy(console, 'error')
|
||||
this.error = requireUncached('./log').error
|
||||
})
|
||||
|
||||
after(function() {
|
||||
this.clock.restore()
|
||||
console.error.restore()
|
||||
Raven.captureException.restore()
|
||||
})
|
||||
|
||||
it('should throttle errors from Raven client', function() {
|
||||
this.error('test error 1')
|
||||
this.error('test error 2')
|
||||
this.error('test error 3')
|
||||
this.clock.tick(11000)
|
||||
this.error('test error 4')
|
||||
this.error('test error 5')
|
||||
|
||||
expect(console.error).to.be.calledWithExactly(
|
||||
'Failed to send captured exception to Sentry',
|
||||
'Cannot send message "test error 1" to Sentry.'
|
||||
)
|
||||
expect(console.error).to.not.be.calledWithExactly(
|
||||
'Failed to send captured exception to Sentry',
|
||||
'Cannot send message "test error 2" to Sentry.'
|
||||
)
|
||||
expect(console.error).to.not.be.calledWithExactly(
|
||||
'Failed to send captured exception to Sentry',
|
||||
'Cannot send message "test error 3" to Sentry.'
|
||||
)
|
||||
expect(console.error).to.be.calledWithExactly(
|
||||
'Failed to send captured exception to Sentry',
|
||||
'Cannot send message "test error 4" to Sentry.'
|
||||
)
|
||||
expect(console.error).to.not.be.calledWithExactly(
|
||||
'Failed to send captured exception to Sentry',
|
||||
'Cannot send message "test error 5" to Sentry.'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
98
package-lock.json
generated
98
package-lock.json
generated
@@ -2597,6 +2597,91 @@
|
||||
"any-observable": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"@sentry/core": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-5.5.0.tgz",
|
||||
"integrity": "sha512-xOcBud0t5mfhFdyd2tQQti4uuWSrLiJihpXzxeRpdCfk2ic+xmpeQs3G4UqnluvQDc48ug/Igt7LXfSBRBx4eg==",
|
||||
"requires": {
|
||||
"@sentry/hub": "5.5.0",
|
||||
"@sentry/minimal": "5.5.0",
|
||||
"@sentry/types": "5.5.0",
|
||||
"@sentry/utils": "5.5.0",
|
||||
"tslib": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"@sentry/hub": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-5.5.0.tgz",
|
||||
"integrity": "sha512-+jKh5U1nv8ufoquGciWoZPOmKuEjFPH5m0VifCs6t3NcEbAq2qnfF26KUGqhUNznlUN/PkbWB4qMfKn14uNE2Q==",
|
||||
"requires": {
|
||||
"@sentry/types": "5.5.0",
|
||||
"@sentry/utils": "5.5.0",
|
||||
"tslib": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"@sentry/minimal": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/minimal/-/minimal-5.5.0.tgz",
|
||||
"integrity": "sha512-o6O30+/pNrO7fTgwKxgZynHB7cMScJlw9HXgnNXgLXS6LBiqjYCQfVnWAgV//SyyG0uUlcjH3P6PnV6TsJOmVQ==",
|
||||
"requires": {
|
||||
"@sentry/hub": "5.5.0",
|
||||
"@sentry/types": "5.5.0",
|
||||
"tslib": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"@sentry/node": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-5.5.0.tgz",
|
||||
"integrity": "sha512-Qn60k7NqJhzpI7PnW/dOz2Y1ofD6kMKGEgLWAO5vcbNShyQj7m2JYFk0c7nFU9HDgertqkxQnvhvIGvT+QokaQ==",
|
||||
"requires": {
|
||||
"@sentry/core": "5.5.0",
|
||||
"@sentry/hub": "5.5.0",
|
||||
"@sentry/types": "5.5.0",
|
||||
"@sentry/utils": "5.5.0",
|
||||
"cookie": "0.3.1",
|
||||
"https-proxy-agent": "2.2.1",
|
||||
"lru_map": "0.3.3",
|
||||
"tslib": "^1.9.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"https-proxy-agent": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz",
|
||||
"integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==",
|
||||
"requires": {
|
||||
"agent-base": "^4.1.0",
|
||||
"debug": "^3.1.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@sentry/types": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.5.0.tgz",
|
||||
"integrity": "sha512-3otF/miVDth91o+iign00x0o31McUPeyIFbMjLbgeTRRW9rXpu2jGrcRrvHfofECtoqCf5Y734hwvvlBvFZeIw=="
|
||||
},
|
||||
"@sentry/utils": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-5.5.0.tgz",
|
||||
"integrity": "sha512-gO8Bs/QcKDn7ncc2f2fIOTPx2AiZKrGj4us1Yxu6mBU8JZqMQRl9XjDMFAUECJQvquBAta+TFJyYj71ZedeQUQ==",
|
||||
"requires": {
|
||||
"@sentry/types": "5.5.0",
|
||||
"tslib": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"@sindresorhus/is": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
|
||||
@@ -3222,7 +3307,6 @@
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz",
|
||||
"integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"es6-promisify": "^5.0.0"
|
||||
}
|
||||
@@ -9069,7 +9153,6 @@
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
|
||||
"integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"es6-promise": "^4.0.3"
|
||||
},
|
||||
@@ -9077,8 +9160,7 @@
|
||||
"es6-promise": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
|
||||
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -15966,6 +16048,11 @@
|
||||
"yallist": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"lru_map": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz",
|
||||
"integrity": "sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0="
|
||||
},
|
||||
"ltcdr": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ltcdr/-/ltcdr-2.2.1.tgz",
|
||||
@@ -24165,8 +24252,7 @@
|
||||
"tslib": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
|
||||
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
||||
},
|
||||
"tsutils": {
|
||||
"version": "3.14.0",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/joi": "^15.1.0",
|
||||
"@sentry/node": "^5.5.0",
|
||||
"bytes": "^3.1.0",
|
||||
"camelcase": "^5.3.1",
|
||||
"camp": "~17.2.4",
|
||||
@@ -54,7 +55,6 @@
|
||||
"priorityqueuejs": "^1.0.0",
|
||||
"prom-client": "^11.5.3",
|
||||
"query-string": "^6.7.0",
|
||||
"raven": "^2.4.2",
|
||||
"request": "~2.88.0",
|
||||
"semver": "~6.2.0",
|
||||
"simple-icons": "1.11.0",
|
||||
|
||||
@@ -8,9 +8,12 @@ require('dotenv').config()
|
||||
|
||||
// Set up Sentry reporting as early in the process as possible.
|
||||
const config = require('config').util.toObject()
|
||||
const Raven = require('raven')
|
||||
Raven.config(process.env.SENTRY_DSN || config.private.sentry_dsn).install()
|
||||
Raven.disableConsoleAlerts()
|
||||
const Sentry = require('@sentry/node')
|
||||
Sentry.init({
|
||||
dsn: process.env.SENTRY_DSN || config.private.sentry_dsn,
|
||||
integrations: integrations =>
|
||||
integrations.filter(integration => integration.name !== 'Console'),
|
||||
})
|
||||
|
||||
if (+process.argv[2]) {
|
||||
config.public.bind.port = +process.argv[2]
|
||||
|
||||
Reference in New Issue
Block a user