Skip to content
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

Propagation of beforeCapture or withErrorBoundary to parent #9091

Closed
3 tasks done
julianCast opened this issue Sep 22, 2023 · 2 comments
Closed
3 tasks done

Propagation of beforeCapture or withErrorBoundary to parent #9091

julianCast opened this issue Sep 22, 2023 · 2 comments

Comments

@julianCast
Copy link
Contributor

julianCast commented Sep 22, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/gatsby

SDK Version

7.67.0

Framework Version

@sentry/react

Steps to Reproduce

I have a root component that wraps other children, and I would like to be able to use both beforeCapture (child and parent) but I'm unable to propagate beforeCapture or any method within withErrorBoundary. Is there a way? Thank you.

export default Sentry.withErrorBoundary(RootElementWrapper, {
  beforeCapture: (scope, error) => {
     console.log("do something else", error);
     scope.setTag("error",error.mesage)
  },
});

and

export default Sentry.withErrorBoundary(PageElementWrapper, {
  beforeCapture: (scope, error) => {
    console.log("do something", error);
    scope.setTag("location","page")
  },
});

Only the child's beforeCapture is working.

Expected Result

Both tags should be set: Child and parent.

Actual Result

Only the child withErrorBoundary is catching the error. The parent ignores it.

Alternative

Could this be a solution, if added to every child? This way the children would set the tag and whenever there is an error, the parent would react with withErrorBoundary.

useEffect(() => {
    Sentry.configureScope((scope) => {
      scope.setTag("location", "checkout");
    });
  }, []);
@AbhiPrasad
Copy link
Member

Hey @julianCast

Due to how error boundaries work, the child error boundary will swallow the error from the parent one. This means only one beforeCapture will fire, since only one error boundary will activate componentDidCatch.

Your suggestion for scope.setTag works well to solve this. An alternative path is to extract this out to a common beforeCapture helper that everything relies on.

@AbhiPrasad AbhiPrasad closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2023
@julianCast
Copy link
Contributor Author

Hey @julianCast

Due to how error boundaries work, the child error boundary will swallow the error from the parent one. This means only one beforeCapture will fire, since only one error boundary will activate componentDidCatch.

Your suggestion for scope.setTag works well to solve this. An alternative path is to extract this out to a common beforeCapture helper that everything relies on.

Thank you for the information!

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

No branches or pull requests

3 participants