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.
Motivation
As of today there are two ways of reporting errors to datadog: uncaught errors that are reported by the SDK automatically, or sending them manually by using
addError
.These methods are efficient for capturing application errors that occur in the client’s browser. In addition to that our APIs also allow for adding custom attributes to errors to make triaging and filtering easier when using Datadog, however the existing API does not make it easy for customers to add these attributes to the error as it’s being sent.
Case 1: An error is explicitly thrown from the customer’s application.
Take a hypothetical scenario where an error is thrown explicitly by a user-defined function.
This error would show up in datadog (unless caught by the caller). However it does not contain information about what led up to the error. Data such as what parameters were used, or what was in the execution context, will not be automatically added by our SDK
Case 2: An error is thrown by a third party dependency.
Similar to the previous case, but now we know that the error will not carry any additional context, in which case it’s the user’s responsibility to add the additional context.
A potential solution would be to catch the error and throw it again, reporting the error with additional context to datadog. This is cumbersome to do and it can also result in the error being reported twice.
Changes
Implement a special error class that inherits from Error that allows for attributes to be passed to error instances
Customers could then throw error with context attached to them explicitly without having to do it when the error is being reported.
When a
RichError
is passed toaddError
it automatically takes theerrorContext
attribute from it and adds it to the payload being sent to datadog. This can be done by either:errorContext
attribute, in which case it will be automatically added to the payloadTesting
I have gone over the contributing documentation.