Skip to content

Easier way to add Sentry to libraries and plugins #1840

@davidbarratt

Description

@davidbarratt

Problem Statement

We want to be aware of when our customers run into problems with our plugin. The most straightforward way to do that is to add Sentry to our plugin:
https://github.com/JoinFlexHealth/woocommerce/blob/a0a66e8ebad2f8368a7f23ea7cd5a79985a104a3/pay-with-flex.php#L52-L222

However, this is a lot of code and it only actually works for exceptions/errors that are handled. We could register the global Sentry client, but we didn't want to takeover an existing client in the code base. Nor do we want to receive events for things that are outside of our control.

Solution Brainstorm

I had two different ideas here:

  1. It would be helpful if the Sentry global could accept a "stack" of clients. It looks like this is almost supported because Hub supports an array of Frame instances, each can have their own client. However, upon further inspection it doesn't look like that would actually work without adding/removing our client from the stack with each function call. I wish the Hub would just loop through all the clients in the stack and report the error to each unique client / DSN. That would also allow our client to be able to filter through all errors.
  2. If you don't want to do that, another thing that would have been super helpful is allowing the default integrations to accept a custom hub/scope rather than the global one. I basically had to copy / re-implement a lot of the default integration code because the only way to use them is with the global instance.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions