This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 135
feat: Sensible non-Error exception serializer #416
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
58bfd6c
feat: Sensible non-Error exception serializer
kamilogorek 9dc385c
feat: Use serialized keys for non-error messages
kamilogorek ebf1997
test: Integration test for non-error ex serializer
kamilogorek e7bc8b5
test: Fix non-errors exception tests for node < 6
kamilogorek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ var transports = require('./transports'); | |
var nodeUtil = require('util'); // nodeUtil to avoid confusion with "utils" | ||
var events = require('events'); | ||
var domain = require('domain'); | ||
var md5 = require('md5'); | ||
|
||
var instrumentor = require('./instrumentation/instrumentor'); | ||
|
||
|
@@ -355,20 +356,36 @@ extend(Raven.prototype, { | |
}, | ||
|
||
captureException: function captureException(err, kwargs, cb) { | ||
if (!(err instanceof Error)) { | ||
// This handles when someone does: | ||
// throw "something awesome"; | ||
// We synthesize an Error here so we can extract a (rough) stack trace. | ||
err = new Error(err); | ||
} | ||
|
||
if (!cb && typeof kwargs === 'function') { | ||
cb = kwargs; | ||
kwargs = {}; | ||
} else { | ||
kwargs = kwargs || {}; | ||
} | ||
|
||
if (!(err instanceof Error)) { | ||
if (utils.isPlainObject(err)) { | ||
// This will allow us to group events based on top-level keys | ||
// which is much better than creating new group when any key/value change | ||
var hash = md5(Object.keys(err).sort()); | ||
var message = 'Sentry: non-Error exception captured [' + hash + ']'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that we need to prefix What about:
^Something like that, only showing the first 2 or 3 keys. That'll be more grokkable than the fingerprint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
var serializedException = utils.serializeException(err); | ||
|
||
kwargs.message = message; | ||
kwargs.fingerprint = [hash]; | ||
kwargs.extra = { | ||
__serialized__: serializedException | ||
}; | ||
|
||
err = new Error(message); | ||
} else { | ||
// This handles when someone does: | ||
// throw "something awesome"; | ||
// We synthesize an Error here so we can extract a (rough) stack trace. | ||
err = new Error(err); | ||
} | ||
} | ||
|
||
var self = this; | ||
var eventId = this.generateEventId(); | ||
parsers.parseError(err, kwargs, function(kw) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, that's a great idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that's awesome kamil. do they need to be hashed? I guess it's a length thing, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without hashing, very large objects will create way too large fingerprints. This way it's always fixed length as you mentioned.