-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report original error from addReactError
instead of fake rendering error
#3285
Closed
eloytoro
wants to merge
3
commits into
DataDog:main
from
eloytoro:eloytoro/report-original-error-react
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import type { ErrorInfo } from 'react' | ||
import type { ErrorWithCause } from '@datadog/browser-core' | ||
import { onReactPluginInit } from '../reactPlugin' | ||
import { callMonitored, clocksNow, createHandlingStack } from '@datadog/browser-core' | ||
import { onRumStart } from '../reactPlugin' | ||
|
||
export function addReactError(error: Error, info: ErrorInfo) { | ||
const renderingError = new Error(error.message) | ||
renderingError.name = 'ReactRenderingError' | ||
renderingError.stack = info.componentStack ?? undefined | ||
;(renderingError as ErrorWithCause).cause = error | ||
onReactPluginInit((_, rumPublicApi) => { | ||
rumPublicApi.addError(renderingError, { framework: 'react' }) | ||
onRumStart((strategy) => { | ||
const handlingStack = createHandlingStack() | ||
BenoitZugmeyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
callMonitored(() => { | ||
strategy.addError({ | ||
error, | ||
handlingStack, | ||
componentStack: info.componentStack ?? undefined, | ||
context: { framework: 'react' }, | ||
startClocks: clocksNow(), | ||
BenoitZugmeyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
}) | ||
}) | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
💬 suggestion: What about also passing the
strategy
inonInit
hook instead ofpublicApi
. This would limit the number of concepts in the React Plugin. To be more explicit we could also rename itstartRumStrategy
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.
Passing the strategy in
onInit
is not that useful because it would be thepreStartStrategy
and there is a good chance that it won't be used right after the hook is called. I think it would make things more complex/confusing for little benefit.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.
in addition to what benoit said, the
preStartStrategy
buffer has already been flushed by the timeonInit
is called, which means that any usage of it would be completely ignoredThere 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.
@eloytoro and I briefly discussed exposing the
lifeCycle
instead of thestrategy
, which might make things more flexible, but for nowstrategy
seems simpler/enough. We can revisit later.