Merge branch 'sentry-context' into 'main'

Sentry: add Soapbox context

See merge request soapbox-pub/soapbox!2804
environments/review-main-yi2y9f/deployments/4159
Alex Gleason 2023-10-13 03:06:12 +00:00
commit 5acdca6d75
3 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ import { startOnboarding } from 'soapbox/actions/onboarding';
import { custom } from 'soapbox/custom'; import { custom } from 'soapbox/custom';
import { queryClient } from 'soapbox/queries/client'; import { queryClient } from 'soapbox/queries/client';
import { selectAccount } from 'soapbox/selectors'; import { selectAccount } from 'soapbox/selectors';
import { unsetSentryAccount } from 'soapbox/sentry';
import KVStore from 'soapbox/storage/kv-store'; import KVStore from 'soapbox/storage/kv-store';
import toast from 'soapbox/toast'; import toast from 'soapbox/toast';
import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth'; import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth';
@ -220,6 +221,9 @@ export const logOut = () =>
queryClient.invalidateQueries(); queryClient.invalidateQueries();
queryClient.clear(); queryClient.clear();
// Clear the account from Sentry.
unsetSentryAccount();
dispatch({ type: AUTH_LOGGED_OUT, account, standalone }); dispatch({ type: AUTH_LOGGED_OUT, account, standalone });
toast.success(messages.loggedOut); toast.success(messages.loggedOut);

Wyświetl plik

@ -1,3 +1,5 @@
import sourceCode from 'soapbox/utils/code';
import type { Account } from './schemas'; import type { Account } from './schemas';
/** Start Sentry. */ /** Start Sentry. */
@ -36,6 +38,8 @@ async function startSentry(dsn: string): Promise<void> {
// for finer control // for finer control
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
}); });
Sentry.setContext('soapbox', sourceCode);
} }
/** Associate the account with Sentry events. */ /** Associate the account with Sentry events. */
@ -45,7 +49,14 @@ async function setSentryAccount(account: Account) {
Sentry.setUser({ Sentry.setUser({
id: account.id, id: account.id,
username: account.acct, username: account.acct,
url: account.url,
}); });
} }
export { startSentry, setSentryAccount }; /** Remove the account from Sentry events. */
async function unsetSentryAccount() {
const Sentry = await import('@sentry/react');
Sentry.setUser(null);
}
export { startSentry, setSentryAccount, unsetSentryAccount };

Wyświetl plik

@ -15,7 +15,7 @@ const tryGit = (cmd: string): string | undefined => {
} }
}; };
const version = (pkg: Record<string, any>) => { const version = (pkg: { version: string }): string => {
// Try to discern from GitLab CI first // Try to discern from GitLab CI first
if (CI_COMMIT_TAG === `v${pkg.version}` || CI_COMMIT_REF_NAME === 'stable') { if (CI_COMMIT_TAG === `v${pkg.version}` || CI_COMMIT_REF_NAME === 'stable') {
return pkg.version; return pkg.version;