Skip to content

feat: capture Error.cause chain in JS error events#774

Open
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
TrevorBurnham:error-cause
Open

feat: capture Error.cause chain in JS error events#774
TrevorBurnham wants to merge 1 commit intoaws-observability:mainfrom
TrevorBurnham:error-cause

Conversation

@TrevorBurnham
Copy link

Resolves #549

Problem

The ES2022 Error.cause property 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 a cause array of { type, message, stack } objects.

Changed files:

  • src/event-schemas/js-error-event.json — added cause array field to the schema
  • src/plugins/utils/js-error-utils.ts — added buildCauseChain() helper; call it from appendErrorObjectDetails() when error.cause is present
  • src/plugins/event-plugins/__tests__/JsErrorPlugin.test.ts — two new tests: nested Error cause chain, and primitive cause value

Example 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.

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
"stack": {
"type": "string"
},
"cause": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Error.cause

2 participants