diff --git a/libraries/logger/logging-manager.coffee b/libraries/logger/logging-manager.coffee index a2e2616193..95fa048740 100644 --- a/libraries/logger/logging-manager.coffee +++ b/libraries/logger/logging-manager.coffee @@ -19,6 +19,9 @@ module.exports = Logger = attributes = {err: new Error(attributes)} # extract any error object error = attributes.err or attributes.error + # avoid reporting errors twice + for key, value of attributes + return if value instanceof Error && value.reportedToSentry # include our log message in the error report if not error? error = {message: message} if typeof message is 'string' @@ -50,6 +53,9 @@ module.exports = Logger = # send the error to sentry try @raven.captureException(error, {tags: tags, extra: extra, level: level}) + # put a flag on the errors to avoid reporting them multiple times + for key, value of attributes + value.reportedToSentry = true if value instanceof Error catch return # ignore any errors diff --git a/libraries/logger/test/unit/coffee/loggingManagerTests.coffee b/libraries/logger/test/unit/coffee/loggingManagerTests.coffee index 307bca4a1e..3b50a880bb 100644 --- a/libraries/logger/test/unit/coffee/loggingManagerTests.coffee +++ b/libraries/logger/test/unit/coffee/loggingManagerTests.coffee @@ -1,3 +1,6 @@ +# run this with +# ./node_modules/.bin/mocha --reporter tap --compilers coffee:coffee-script/register test/unit/coffee/loggingManagerTests.coffee + require('coffee-script') chai = require('chai') should = chai.should() @@ -24,6 +27,18 @@ describe 'logger.error', -> @logger.error {foo:'bar'}, "message" @captureException.called.should.equal true + it 'should report the same error to sentry only once', () -> + error1 = new Error('this is the error') + @logger.error {foo: error1}, "first message" + @logger.error {bar: error1}, "second message" + @captureException.callCount.should.equal 1 + + it 'should report two different errors to sentry individually', () -> + error1 = new Error('this is the error') + error2 = new Error('this is the error') + @logger.error {foo: error1}, "first message" + @logger.error {bar: error2}, "second message" + @captureException.callCount.should.equal 2 it 'for multiple errors should only report a maximum of 5 errors to sentry', () -> @logger.error {foo:'bar'}, "message"