-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10162 from DestinyItemManager/include-sentry
Always include Sentry, just disable reporting
- Loading branch information
Showing
5 changed files
with
96 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)[] = [ | ||
|
@@ -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); | ||
}); | ||
}; |