Skip to content

Commit e9aacc4

Browse files
🐛 Support error.dd_context for addReactError API (#3791)
1 parent 084b7ac commit e9aacc4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/rum-react/src/domain/error/addReactError.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,26 @@ describe('addReactError', () => {
3939
}
4040
)
4141
})
42+
43+
it('should merge dd_context from the original error with react error context', () => {
44+
const addEventSpy = jasmine.createSpy()
45+
initializeReactPlugin({
46+
addEvent: addEventSpy,
47+
})
48+
const originalError = new Error('error message')
49+
originalError.name = 'CustomError'
50+
;(originalError as any).dd_context = { component: 'Menu', param: 123 }
51+
52+
addReactError(originalError, {})
53+
54+
expect(addEventSpy.calls.mostRecent().args[1]).toEqual(
55+
jasmine.objectContaining({
56+
context: {
57+
framework: 'react',
58+
component: 'Menu',
59+
param: 123,
60+
},
61+
})
62+
)
63+
})
4264
})

packages/rum-react/src/domain/error/addReactError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function addReactError(error: Error, info: ErrorInfo) {
4545
source_type: 'browser',
4646
csp: rawError.csp,
4747
},
48-
context: { framework: 'react' },
48+
context: { framework: 'react', ...rawError.context },
4949
},
5050
{
5151
error: rawError.originalError,

0 commit comments

Comments
 (0)