Skip to content

Commit

Permalink
Merge pull request #10162 from DestinyItemManager/include-sentry
Browse files Browse the repository at this point in the history
Always include Sentry, just disable reporting
  • Loading branch information
bhollis authored Dec 11, 2023
2 parents 057fd92 + 3830fe0 commit e268fc4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 113 deletions.
2 changes: 1 addition & 1 deletion config/content-security-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const SELF = "'self'";
export default function csp(
env: 'release' | 'beta' | 'dev' | 'pr',
featureFlags: FeatureFlags,
version: string | undefined
version: string | undefined,
) {
const baseCSP: Record<string, string[] | string | boolean> = {
defaultSrc: ["'none'"],
Expand Down
4 changes: 2 additions & 2 deletions src/app/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import store from './store/store';
import { isNativeDragAndDropSupported } from './utils/browsers';

// Wrap App with Sentry profiling
const WrappedApp = $featureFlags.sentry ? withProfiler(App) : App;
const ProfiledApp = withProfiler(App);

function Root() {
const options: MultiBackendOptions = {
Expand All @@ -41,7 +41,7 @@ function Root() {
<Provider store={store}>
<LocationSwitcher />
<DndProvider options={options}>
<WrappedApp />
<ProfiledApp />
</DndProvider>
</Provider>
</Router>
Expand Down
6 changes: 2 additions & 4 deletions src/app/inventory/d2-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { processInGameLoadouts } from 'app/loadout-drawer/loadout-type-converter
import { inGameLoadoutLoaded } from 'app/loadout/ingame/actions';
import { loadCoreSettings } from 'app/manifest/actions';
import { d2ManifestSelector, manifestSelector } from 'app/manifest/selectors';
import { loadingTracker } from 'app/shell/loading-tracker';
import { get, set } from 'app/storage/idb-keyval';
import { ThunkResult } from 'app/store/types';
import { convertToError, errorMessage } from 'app/utils/errors';
Expand All @@ -20,7 +21,6 @@ import { bungieErrorToaster } from '../bungie-api/error-toaster';
import { D2ManifestDefinitions, getDefinitions } from '../destiny2/d2-definitions';
import { bungieNetPath } from '../dim-ui/BungieImage';
import { showNotification } from '../notifications/notifications';
import { loadingTracker } from '../shell/loading-tracker';
import { reportException } from '../utils/sentry';
import {
CharacterInfo,
Expand Down Expand Up @@ -255,9 +255,7 @@ function loadStoresData(
return;
}

const transaction = $featureFlags.sentry
? startTransaction({ name: 'loadStoresD2' })
: undefined;
const transaction = startTransaction({ name: 'loadStoresD2' });
// set the transaction on the scope so it picks up any errors
getCurrentHub()?.configureScope((scope) => scope.setSpan(transaction));

Expand Down
10 changes: 4 additions & 6 deletions src/app/register-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ export default function registerServiceWorker() {
if (registration.waiting) {
infoLog('SW', 'New content is available; please refresh. (from update)');

if ($featureFlags.sentry) {
// Disable Sentry error logging if this user is on an older version
const sentryOptions = getCurrentHub()?.getClient()?.getOptions();
if (sentryOptions) {
sentryOptions.enabled = false;
}
// Disable Sentry error logging if this user is on an older version
const sentryOptions = getCurrentHub()?.getClient()?.getOptions();
if (sentryOptions) {
sentryOptions.enabled = false;
}

return true;
Expand Down
187 changes: 87 additions & 100 deletions src/app/utils/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ import { HashLookupFailure } from 'app/destiny2/definitions';
import { defaultLanguage } from 'app/i18n';
import { PlatformErrorCodes } from 'bungie-api-ts/user';
import { DimError } from './dim-error';
import { errorLog } from './log';

/** Sentry.io exception reporting */
export let reportException = (name: string, e: any, errorInfo?: Record<string, unknown>) => {
errorLog(
'exception',
name,
e,
errorInfo,
e instanceof DimError && e.code,
e instanceof DimError && e.cause,
);
};

// DIM error codes to ignore and not report. This works regardless of language.
const ignoreDimErrors: (string | PlatformErrorCodes)[] = [
Expand All @@ -40,106 +27,106 @@ const ignoreDimErrors: (string | PlatformErrorCodes)[] = [
PlatformErrorCodes.DestinyCannotPerformActionAtThisLocation,
];

if ($featureFlags.sentry) {
const options: BrowserOptions = {
dsn: 'https://[email protected]/279673',
release: $DIM_VERSION,
environment: $DIM_FLAVOR,
ignoreErrors: [],
sampleRate: $DIM_VERSION === 'beta' ? 0.5 : 0.01, // Sample Beta at 50%, Prod at 1%
attachStacktrace: true,
integrations: [
new BrowserTracing({
// Only send trace headers to our own server
tracePropagationTargets: ['api.destinyitemmanager.com'],
beforeNavigate: (context) => ({
...context,
// We could use the React-Router integration but it's annoying
name: window.location.pathname
.replace(/\/\d+\/d(1|2)/g, '/profileMembershipId/d$1')
.replace(/\/vendors\/\d+/g, '/vendors/vendorId')
.replace(/index\.html/, ''),
}),
const options: BrowserOptions = {
enabled: $featureFlags.sentry,
dsn: 'https://[email protected]/279673',
release: $DIM_VERSION,
environment: $DIM_FLAVOR,
ignoreErrors: [],
sampleRate: $DIM_VERSION === 'beta' ? 0.5 : 0.01, // Sample Beta at 50%, Prod at 1%
attachStacktrace: true,
integrations: [
new BrowserTracing({
// Only send trace headers to our own server
tracePropagationTargets: ['api.destinyitemmanager.com'],
beforeNavigate: (context) => ({
...context,
// We could use the React-Router integration but it's annoying
name: window.location.pathname
.replace(/\/\d+\/d(1|2)/g, '/profileMembershipId/d$1')
.replace(/\/vendors\/\d+/g, '/vendors/vendorId')
.replace(/index\.html/, ''),
}),
],
tracesSampleRate: 0.001, // Performance traces at 0.1%
beforeSend: (event, hint) => {
const e = hint?.originalException;
const underlyingError = e instanceof DimError ? e.cause : undefined;
}),
],
tracesSampleRate: 0.001, // Performance traces at 0.1%
beforeSend: (event, hint) => {
const e = hint?.originalException;
const underlyingError = e instanceof DimError ? e.cause : undefined;

const code =
underlyingError instanceof BungieError
? underlyingError.code
: e instanceof DimError
? e.code
: undefined;
if (code && ignoreDimErrors.includes(code)) {
return null; // drop report
}
if (e instanceof HashLookupFailure) {
// Add the ID to the fingerprint so we don't collapse different errors
event.fingerprint = ['{{ default }}', String(e.table), String(e.id)];
}
if (e instanceof DimError) {
// Replace the (localized) message with our code
event.message = e.code;
// TODO: it might be neat to be able to pass attachments here too - such as the entire profile response!
const code =
underlyingError instanceof BungieError
? underlyingError.code
: e instanceof DimError
? e.code
: undefined;
if (code && ignoreDimErrors.includes(code)) {
return null; // drop report
}
if (e instanceof HashLookupFailure) {
// Add the ID to the fingerprint so we don't collapse different errors
event.fingerprint = ['{{ default }}', String(e.table), String(e.id)];
}
if (e instanceof DimError) {
// Replace the (localized) message with our code
event.message = e.code;
// TODO: it might be neat to be able to pass attachments here too - such as the entire profile response!

// Do deeper surgery to overwrite the localized message with the code
if (event.exception?.values) {
for (const ex of event.exception.values) {
if (ex.value === e.message) {
ex.value = e.code;
}
// Do deeper surgery to overwrite the localized message with the code
if (event.exception?.values) {
for (const ex of event.exception.values) {
if (ex.value === e.message) {
ex.value = e.code;
}
}
}

event.tags = {
...event.tags,
code: e.code,
};
if (underlyingError instanceof BungieError) {
event.tags = {
...event.tags,
code: e.code,
bungieErrorCode: underlyingError.code,
};
if (underlyingError instanceof BungieError) {
event.tags = {
...event.tags,
bungieErrorCode: underlyingError.code,
};
}
}

if (underlyingError) {
event.extra = {
...event.extra,
cause: underlyingError,
};
}
if (underlyingError) {
event.extra = {
...event.extra,
cause: underlyingError,
};
}
}

return event;
},
};
return event;
},
};

// TODO: There's a redux integration but I'm worried it'd be too much trouble to trim out all the stuff we wouldn't want to report (by default it sends the whole action & state.
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/redux/
addTracingExtensions();
init(options);
// TODO: There's a redux integration but I'm worried it'd be too much trouble to trim out all the stuff we wouldn't want to report (by default it sends the whole action & state.
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/redux/
addTracingExtensions();
init(options);

// Set user ID (membership ID) to help debug and to better count affected users
const token = getToken();
if (token?.bungieMembershipId) {
setUser({ id: token.bungieMembershipId });
}
// Set user ID (membership ID) to help debug and to better count affected users
const token = getToken();
if (token?.bungieMembershipId) {
setUser({ id: token.bungieMembershipId });
}

// Capture locale
setTag('lang', defaultLanguage());
// Capture locale
setTag('lang', defaultLanguage());

reportException = (name: string, e: any, errorInfo?: Record<string, unknown>) => {
// TODO: we can also do this in some situations to gather more feedback from users
// Sentry.showReportDialog();
withScope((scope) => {
setTag('context', name);
if (errorInfo) {
scope.setExtras(errorInfo);
}
captureException(e);
});
};
}
/** Sentry.io exception reporting */
export const reportException = (name: string, e: any, errorInfo?: Record<string, unknown>) => {
// TODO: we can also do this in some situations to gather more feedback from users
// Sentry.showReportDialog();
withScope((scope) => {
setTag('context', name);
if (errorInfo) {
scope.setExtras(errorInfo);
}
captureException(e);
});
};

0 comments on commit e268fc4

Please sign in to comment.