-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02e4e17
commit a78614f
Showing
8 changed files
with
3,381 additions
and
4,107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ cypress/screenshots | |
#swc | ||
.swc | ||
.cypress_cache | ||
|
||
# Sentry Config File | ||
.env.sentry-build-plugin |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import { BrowserTracing } from '@sentry/tracing'; | ||
import * as SentryBrowser from '@sentry/browser'; | ||
import { ChromeUser } from '@redhat-cloud-services/types'; | ||
import { isProd } from './common'; | ||
|
||
|
@@ -31,24 +31,25 @@ function getAppDetails() { | |
|
||
return appDetails; | ||
} | ||
const EXTRA_KEY = 'ROUTE_TO'; | ||
|
||
const transport = SentryBrowser.makeMultiplexedTransport(SentryBrowser.makeFetchTransport, (args) => { | ||
const event = args.getEvent(); | ||
if (event && event.extra && EXTRA_KEY in event.extra && Array.isArray(event.extra[EXTRA_KEY])) { | ||
return event.extra[EXTRA_KEY]; | ||
} | ||
return []; | ||
}); | ||
|
||
// Actually initialize sentry with the group's api key | ||
function initSentry() { | ||
if (sentryInitialized) { | ||
return; | ||
} | ||
|
||
sentryInitialized = true; | ||
const appDetails = getAppDetails(); | ||
|
||
let API_KEY; | ||
switch (appDetails.app.name) { | ||
case 'advisor': | ||
API_KEY = 'https://[email protected]/4505397435367424'; | ||
break; | ||
default: | ||
API_KEY = 'https://[email protected]/1484024'; | ||
} | ||
//These two apps will not be set up as of now. This helps limit transacations | ||
const avoidedApps = ['subscriptions', 'image-builder']; | ||
|
||
// dsn: key | ||
// environment: logs Prod or Prod Beta for filtering | ||
|
@@ -61,17 +62,50 @@ function initSentry() { | |
// maskeAllText: mask all text on the screen. | ||
// ignoreErrors: Sentry ignores errors containing strings or regex. Regex needs to be exact message, string is partial | ||
// replaysSessionSampleRate: replays that begin recording immediately and last the entirety of the user's session. | ||
|
||
// transport is what allows consumed apps to tell chrome what dsn to send things too. | ||
Sentry.init({ | ||
dsn: API_KEY, | ||
//default api_key -> cp-001-insights | ||
dsn: 'https://[email protected]/1484024', | ||
environment: `Prod${appDetails.beta}`, | ||
maxBreadcrumbs: 50, | ||
attachStacktrace: true, | ||
integrations: [new BrowserTracing(), new Sentry.Replay({ maskAllText: false, maskAllInputs: true })], | ||
tracesSampleRate: 0.2, | ||
integrations: [ | ||
Sentry.browserTracingIntegration(), | ||
Sentry.replayIntegration({ maskAllText: false, maskAllInputs: true }), | ||
Sentry.moduleMetadataIntegration(), | ||
], | ||
tracesSampleRate: 0.1, | ||
debug: !!window.localStorage.getItem('chrome:sentry:debug'), | ||
replaysOnErrorSampleRate: 1.0, | ||
replaysSessionSampleRate: 0.3, | ||
transport, | ||
beforeSend: (event) => { | ||
if (event?.exception?.values?.[0]?.stacktrace?.frames) { | ||
const frames = event.exception.values[0].stacktrace.frames; | ||
// Find the last frame with module metadata containing a DSN | ||
const routeTo = frames | ||
.filter((frame) => frame.module_metadata && frame.module_metadata.dsn) | ||
.map((v) => v.module_metadata) | ||
.slice(-1); // using top frame only - you may want to customize this according to your needs | ||
|
||
if (routeTo.length) { | ||
event.extra = { | ||
...event.extra, | ||
[EXTRA_KEY]: routeTo, | ||
}; | ||
} | ||
} | ||
|
||
return event; | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
beforeSendTransaction: (event: any) => { | ||
const appName = event?.contexts?.app?.app_name; | ||
if (avoidedApps.includes(appName)) { | ||
return null; | ||
} | ||
return event; | ||
}, | ||
}); | ||
} | ||
|
||
|
@@ -83,17 +117,16 @@ function sentryTags(user: ChromeUser) { | |
const browser_width = window.innerWidth + ' px'; | ||
|
||
// TODO: Add request_id to this when we have it | ||
Sentry.configureScope((scope) => { | ||
scope.setUser({ | ||
id: user.identity.account_number, | ||
account_id: user.identity.internal?.account_id, | ||
}); | ||
scope.setTags({ | ||
app_name: appDetails.app.name, | ||
app_group: appDetails.app.group, | ||
location: 'frontend', | ||
browser_width: browser_width, | ||
}); | ||
const scope = SentryBrowser.getCurrentScope(); | ||
scope.setUser({ | ||
id: user.identity.account_number, | ||
account_id: user.identity.internal?.account_id, | ||
}); | ||
scope.setTags({ | ||
app_name: appDetails.app.name, | ||
app_group: appDetails.app.group, | ||
location: 'frontend', | ||
browser_width: browser_width, | ||
}); | ||
} | ||
|
||
|