Overview
Our Javascript application uses Angular and TypeScript, with Sentry.io for error reporting. If an error occurs, a custom modal allows users to leave a message, which should be sent to Sentry when they click submit.
Issue
We have noticed that messages are not being received by Sentry if it is inaccessible, such as being blocked by an ad blocker plugin in the browser.
Objective
Our goal is to provide users with instructions to contact support if Sentry is unavailable, or allow them to send a message through Sentry but provide alternative support options if the message sending fails.
Approaches Attempted
We have explored using Sentry's Sentry.captureMessage(…)
and Sentry.flush(…)
, but these methods do not indicate if the POST request was successful. We developed a workaround by checking if Sentry is blocked internally.
public sentryIsBlocked() : boolean | null {
const client = Sentry.getCurrentHub().getClient();
// Check if Sentry is reachable
if (!client) return null;
const numberOfNetworkSessionErrors = (client as any)['_outcomes']['network_error:session'];
return !!numberOfNetworkSessionErrors && numberOfNetworkSessionErrors > 0;
}
While this solution works, there are drawbacks:
- It may break with Sentry updates as it relies on non-public API objects.
- The method returns true if any past request to Sentry had issues, which does not guarantee current success.
Inquiry
Is there a way to determine if a POST request made by Sentry.captureMessage(…)
or Sentry.captureException(…)
encounters an error?