Automatic error reporting (#7046)

* Enable sentry global handlers if automaticErrorReporting is on

* Pass the exception through on session restore error

Passing the exception object itself through to the BugReportDialog means a stack trace can be correctly recorded in Sentry
This commit is contained in:
James Salter 2021-10-29 09:34:25 +01:00 committed by GitHub
parent d0bb6e0657
commit 3defb863b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 12 deletions

View file

@ -192,6 +192,11 @@ export async function sendSentryReport(userText: string, issueUrl: string, error
}
}
export function setSentryUser(mxid: string): void {
if (!SdkConfig.get().sentry || !SettingsStore.getValue("automaticErrorReporting")) return;
Sentry.setUser({ username: mxid });
}
interface ISentryConfig {
dsn: string;
environment?: string;
@ -199,21 +204,28 @@ interface ISentryConfig {
export async function initSentry(sentryConfig: ISentryConfig): Promise<void> {
if (!sentryConfig) return;
// Only enable Integrations.GlobalHandlers, which hooks uncaught exceptions, if automaticErrorReporting is true
const integrations = [
new Sentry.Integrations.InboundFilters(),
new Sentry.Integrations.FunctionToString(),
new Sentry.Integrations.Breadcrumbs(),
new Sentry.Integrations.UserAgent(),
new Sentry.Integrations.Dedupe(),
];
if (SettingsStore.getValue("automaticErrorReporting")) {
integrations.push(new Sentry.Integrations.GlobalHandlers(
{ onerror: false, onunhandledrejection: true }));
integrations.push(new Sentry.Integrations.TryCatch());
}
Sentry.init({
dsn: sentryConfig.dsn,
release: process.env.VERSION,
environment: sentryConfig.environment,
defaultIntegrations: false,
autoSessionTracking: false,
integrations: [
// specifically disable Integrations.GlobalHandlers, which hooks uncaught exceptions - we don't
// want to capture those at this stage, just explicit rageshakes
new Sentry.Integrations.InboundFilters(),
new Sentry.Integrations.FunctionToString(),
new Sentry.Integrations.Breadcrumbs(),
new Sentry.Integrations.UserAgent(),
new Sentry.Integrations.Dedupe(),
],
integrations,
// Set to 1.0 which is reasonable if we're only submitting Rageshakes; will need to be set < 1.0
// if we collect more frequently.
tracesSampleRate: 1.0,