mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Restricted Sentry event capturing to portal events
no refs - updates Sentry's `beforeSend` method to restrict and send events originated by portal
This commit is contained in:
parent
60c4ba5888
commit
0dcf06da99
@ -10,7 +10,7 @@ import * as Fixtures from './utils/fixtures';
|
||||
import ActionHandler from './actions';
|
||||
import './App.css';
|
||||
import NotificationParser from './utils/notifications';
|
||||
import {createPopupNotification, getCurrencySymbol, getFirstpromoterId, getQueryPrice, getSiteDomain, isComplimentaryMember, isInviteOnlySite, removePortalLinkFromUrl} from './utils/helpers';
|
||||
import {createPopupNotification, getCurrencySymbol, getFirstpromoterId, getQueryPrice, getSiteDomain, isComplimentaryMember, isInviteOnlySite, isSentryEventAllowed, removePortalLinkFromUrl} from './utils/helpers';
|
||||
|
||||
const handleDataAttributes = require('./data-attributes');
|
||||
const React = require('react');
|
||||
@ -21,6 +21,23 @@ const DEV_MODE_DATA = {
|
||||
member: Fixtures.member.paid,
|
||||
page: 'signup'
|
||||
};
|
||||
|
||||
function SentryErrorBoundary({site, children}) {
|
||||
const {portal_sentry: portalSentry} = site || {};
|
||||
if (portalSentry && portalSentry.dsn) {
|
||||
return (
|
||||
<Sentry.ErrorBoundary>
|
||||
{children}
|
||||
</Sentry.ErrorBoundary>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -385,6 +402,12 @@ export default class App extends React.Component {
|
||||
dsn: portalSentry.dsn,
|
||||
environment: portalSentry.env || 'development',
|
||||
release: releaseTag,
|
||||
beforeSend: (event) => {
|
||||
if (isSentryEventAllowed({event})) {
|
||||
return event;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
allowUrls: [
|
||||
/https?:\/\/((www)\.)?unpkg\.com\/@tryghost\/portal/
|
||||
]
|
||||
@ -609,13 +632,13 @@ export default class App extends React.Component {
|
||||
render() {
|
||||
if (this.state.initStatus === 'success') {
|
||||
return (
|
||||
<Sentry.ErrorBoundary>
|
||||
<SentryErrorBoundary site={this.state.site}>
|
||||
<AppContext.Provider value={this.getContextFromState()}>
|
||||
<PopupModal />
|
||||
<TriggerButton />
|
||||
<Notification />
|
||||
</AppContext.Provider>
|
||||
</Sentry.ErrorBoundary>
|
||||
</SentryErrorBoundary>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
@ -27,6 +27,13 @@ export function isCookiesDisabled() {
|
||||
return !(navigator && navigator.cookieEnabled);
|
||||
}
|
||||
|
||||
export function isSentryEventAllowed({event: sentryEvent}) {
|
||||
const frames = sentryEvent?.exception?.values?.[0]?.stacktrace?.frames || [];
|
||||
const fileNames = frames.map(frame => frame.filename).filter(filename => !!filename);
|
||||
const lastFileName = fileNames[fileNames.length - 1] || '';
|
||||
return lastFileName.includes('@tryghost/portal');
|
||||
}
|
||||
|
||||
export function getMemberSubscription({member = {}}) {
|
||||
if (isPaidMember({member})) {
|
||||
const subscriptions = member.subscriptions || [];
|
||||
|
Loading…
Reference in New Issue
Block a user