feat: capture Error.cause chain in JS error events#774
Open
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
Open
feat: capture Error.cause chain in JS error events#774TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
Conversation
Add support for the ES2022 Error.cause property when recording JS
errors. The cause chain is walked recursively (up to 5 levels) and
stored as an array of {type, message, stack} objects on the event.
Resolves aws-observability#549
williazz
reviewed
Mar 23, 2026
| "stack": { | ||
| "type": "string" | ||
| }, | ||
| "cause": { |
Collaborator
There was a problem hiding this comment.
There are unfortunately some backend changes we need to for this. Thanks for addressing this issue from years back. I'll merge this in as soon as we are ready for it.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #549
Problem
The ES2022
Error.causeproperty allows developers to wrap lower-level errors with higher-level context. The RUM web client currently ignores this property, so the causal chain is lost when JS errors are recorded.Solution
Walk
error.cause(up to 5 levels) and attach the chain to the RUM event as acausearray of{ type, message, stack }objects.Changed files:
src/event-schemas/js-error-event.json— addedcausearray field to the schemasrc/plugins/utils/js-error-utils.ts— addedbuildCauseChain()helper; call it fromappendErrorObjectDetails()whenerror.causeis presentsrc/plugins/event-plugins/__tests__/JsErrorPlugin.test.ts— two new tests: nested Error cause chain, and primitive cause valueExample output
{ "version": "1.0.0", "type": "Error", "message": "Request handler failed", "stack": "...", "cause": [ { "type": "Error", "message": "Database query failed", "stack": "..." }, { "type": "TypeError", "message": "null is not an object", "stack": "..." } ] }By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.