2023-10-21 10:43:32 -07:00
|
|
|
import { NODE_ENV } from 'soapbox/build-config';
|
2023-10-12 19:51:06 -07:00
|
|
|
import sourceCode from 'soapbox/utils/code';
|
|
|
|
|
2023-10-12 18:07:48 -07:00
|
|
|
import type { Account } from './schemas';
|
|
|
|
|
2023-10-05 14:33:59 -07:00
|
|
|
/** Start Sentry. */
|
|
|
|
async function startSentry(dsn: string): Promise<void> {
|
|
|
|
const [Sentry, { Integrations: Integrations }] = await Promise.all([
|
|
|
|
import('@sentry/react'),
|
|
|
|
import('@sentry/tracing'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
Sentry.init({
|
|
|
|
dsn,
|
|
|
|
debug: false,
|
2023-10-21 10:43:32 -07:00
|
|
|
enabled: NODE_ENV === 'production',
|
2023-10-05 14:33:59 -07:00
|
|
|
integrations: [new Integrations.BrowserTracing()],
|
|
|
|
|
|
|
|
// Filter events.
|
|
|
|
// https://docs.sentry.io/platforms/javascript/configuration/filtering/
|
|
|
|
ignoreErrors: [
|
|
|
|
// Network errors.
|
|
|
|
'AxiosError',
|
|
|
|
// sw.js couldn't be downloaded.
|
|
|
|
'Failed to update a ServiceWorker for scope',
|
|
|
|
// Useful for try/catch, useless as a Sentry error.
|
|
|
|
'AbortError',
|
|
|
|
// localForage error in FireFox private browsing mode (which doesn't support IndexedDB).
|
|
|
|
// We only use IndexedDB as a cache, so we can safely ignore the error.
|
|
|
|
'No available storage method found',
|
2023-10-15 15:12:48 -07:00
|
|
|
// Virtuoso throws these errors, but it is a false-positive.
|
|
|
|
// https://github.com/petyosi/react-virtuoso/issues/254
|
|
|
|
'ResizeObserver loop completed with undelivered notifications.',
|
|
|
|
'ResizeObserver loop limit exceeded',
|
2023-10-05 14:33:59 -07:00
|
|
|
],
|
|
|
|
denyUrls: [
|
|
|
|
// Browser extensions.
|
|
|
|
/extensions\//i,
|
|
|
|
/^chrome:\/\//i,
|
|
|
|
/^moz-extension:\/\//i,
|
|
|
|
],
|
|
|
|
|
|
|
|
tracesSampleRate: 1.0,
|
|
|
|
});
|
2023-10-12 19:51:06 -07:00
|
|
|
|
|
|
|
Sentry.setContext('soapbox', sourceCode);
|
2023-10-05 14:33:59 -07:00
|
|
|
}
|
|
|
|
|
2023-10-12 18:07:48 -07:00
|
|
|
/** Associate the account with Sentry events. */
|
|
|
|
async function setSentryAccount(account: Account) {
|
|
|
|
const Sentry = await import('@sentry/react');
|
|
|
|
|
|
|
|
Sentry.setUser({
|
|
|
|
id: account.id,
|
|
|
|
username: account.acct,
|
2023-10-12 19:51:06 -07:00
|
|
|
url: account.url,
|
2023-10-12 18:07:48 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-12 19:56:14 -07:00
|
|
|
/** Remove the account from Sentry events. */
|
|
|
|
async function unsetSentryAccount() {
|
|
|
|
const Sentry = await import('@sentry/react');
|
|
|
|
Sentry.setUser(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
export { startSentry, setSentryAccount, unsetSentryAccount };
|