Send username/id to Sentry

This commit is contained in:
Alex Gleason 2023-10-12 20:07:48 -05:00
parent 2cdfaf4871
commit a98dfd8c11
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 23 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import { selectAccount } from 'soapbox/selectors';
import { setSentryAccount } from 'soapbox/sentry';
import KVStore from 'soapbox/storage/kv-store';
import { getAuthUserId, getAuthUserUrl } from 'soapbox/utils/auth';
@ -8,6 +9,7 @@ import { loadCredentials } from './auth';
import { importFetchedAccount } from './importer';
import type { AxiosError, RawAxiosRequestHeaders } from 'axios';
import type { Account } from 'soapbox/schemas';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
@ -88,10 +90,14 @@ const fetchMeRequest = () => ({
type: ME_FETCH_REQUEST,
});
const fetchMeSuccess = (me: APIEntity) => ({
const fetchMeSuccess = (account: Account) => {
setSentryAccount(account);
return {
type: ME_FETCH_SUCCESS,
me,
});
me: account,
};
};
const fetchMeFail = (error: APIEntity) => ({
type: ME_FETCH_FAIL,

View file

@ -1,3 +1,5 @@
import type { Account } from './schemas';
/** Start Sentry. */
async function startSentry(dsn: string): Promise<void> {
const [Sentry, { Integrations: Integrations }] = await Promise.all([
@ -36,4 +38,14 @@ async function startSentry(dsn: string): Promise<void> {
});
}
export { startSentry };
/** 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,
});
}
export { startSentry, setSentryAccount };