diff --git a/CHANGELOG.md b/CHANGELOG.md index 635e8616..740c3649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +- Add Sentry error tracking + ## [5.6.0] - 2017-03-23 ### Added diff --git a/build/app.js b/build/app.js index 71e77d22..7dc905b4 100644 --- a/build/app.js +++ b/build/app.js @@ -15,7 +15,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var Promise, _, actions, capitano, errors, events, plugins, resin, update; +var Promise, Raven, _, actions, capitano, errors, events, plugins, resin, update; + +Raven = require('raven'); + +Raven.disableConsoleAlerts(); + +Raven.config('https://56d2a46124614b01b0f4086897e96110:6e175465accc41b595a96947155f61fb@sentry.io/149239', { + captureUnhandledRejections: true, + release: require('../package.json').version +}).install(); _ = require('lodash'); diff --git a/build/errors.js b/build/errors.js index 3877f5c0..5d9df00d 100644 --- a/build/errors.js +++ b/build/errors.js @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var chalk, errors, patterns; +var Promise, Raven, captureException, chalk, errors, patterns; chalk = require('chalk'); @@ -23,6 +23,12 @@ errors = require('resin-cli-errors'); patterns = require('./utils/patterns'); +Raven = require('raven'); + +Promise = require('bluebird'); + +captureException = Promise.promisify(Raven.captureException.bind(Raven)); + exports.handle = function(error) { var message; message = errors.interpret(error); @@ -33,5 +39,7 @@ exports.handle = function(error) { message = error.stack; } patterns.printErrorMessage(message); - return process.exit(error.exitCode || 1); + return captureException(error).timeout(1000)["catch"](function() {})["finally"](function() { + return process.exit(error.exitCode || 1); + }); }; diff --git a/lib/app.coffee b/lib/app.coffee index 5cb1b164..74d5055d 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -14,6 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ### +Raven = require('raven') +Raven.disableConsoleAlerts() +Raven.config( + 'https://56d2a46124614b01b0f4086897e96110:6e175465accc41b595a96947155f61fb@sentry.io/149239' + captureUnhandledRejections: true + release: require('../package.json').version +).install() + _ = require('lodash') Promise = require('bluebird') capitano = Promise.promisifyAll(require('capitano')) diff --git a/lib/errors.coffee b/lib/errors.coffee index bac4b2c1..297cb5d0 100644 --- a/lib/errors.coffee +++ b/lib/errors.coffee @@ -17,6 +17,10 @@ limitations under the License. chalk = require('chalk') errors = require('resin-cli-errors') patterns = require('./utils/patterns') +Raven = require('raven') +Promise = require('bluebird') + +captureException = Promise.promisify(Raven.captureException.bind(Raven)) exports.handle = (error) -> message = errors.interpret(error) @@ -26,4 +30,9 @@ exports.handle = (error) -> message = error.stack patterns.printErrorMessage(message) - process.exit(error.exitCode or 1) + + captureException(error) + .timeout(1000) + .catch(-> # Ignore any errors (from error logging, or timeouts) + ).finally -> + process.exit(error.exitCode or 1) diff --git a/package.json b/package.json index 0a371ba6..83288096 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "president": "^2.0.1", "prettyjson": "^1.1.3", "reconfix": "^0.0.3", + "raven": "^1.2.0", "resin-cli-auth": "^1.0.0", "resin-cli-errors": "^1.2.0", "resin-cli-form": "^1.4.1",