mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05: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
2 changed files with 33 additions and 3 deletions
|
@ -10,7 +10,7 @@ import * as Fixtures from './utils/fixtures';
|
||||||
import ActionHandler from './actions';
|
import ActionHandler from './actions';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import NotificationParser from './utils/notifications';
|
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 handleDataAttributes = require('./data-attributes');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
@ -21,6 +21,23 @@ const DEV_MODE_DATA = {
|
||||||
member: Fixtures.member.paid,
|
member: Fixtures.member.paid,
|
||||||
page: 'signup'
|
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 {
|
export default class App extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -385,6 +402,12 @@ export default class App extends React.Component {
|
||||||
dsn: portalSentry.dsn,
|
dsn: portalSentry.dsn,
|
||||||
environment: portalSentry.env || 'development',
|
environment: portalSentry.env || 'development',
|
||||||
release: releaseTag,
|
release: releaseTag,
|
||||||
|
beforeSend: (event) => {
|
||||||
|
if (isSentryEventAllowed({event})) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
allowUrls: [
|
allowUrls: [
|
||||||
/https?:\/\/((www)\.)?unpkg\.com\/@tryghost\/portal/
|
/https?:\/\/((www)\.)?unpkg\.com\/@tryghost\/portal/
|
||||||
]
|
]
|
||||||
|
@ -609,13 +632,13 @@ export default class App extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
if (this.state.initStatus === 'success') {
|
if (this.state.initStatus === 'success') {
|
||||||
return (
|
return (
|
||||||
<Sentry.ErrorBoundary>
|
<SentryErrorBoundary site={this.state.site}>
|
||||||
<AppContext.Provider value={this.getContextFromState()}>
|
<AppContext.Provider value={this.getContextFromState()}>
|
||||||
<PopupModal />
|
<PopupModal />
|
||||||
<TriggerButton />
|
<TriggerButton />
|
||||||
<Notification />
|
<Notification />
|
||||||
</AppContext.Provider>
|
</AppContext.Provider>
|
||||||
</Sentry.ErrorBoundary>
|
</SentryErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -27,6 +27,13 @@ export function isCookiesDisabled() {
|
||||||
return !(navigator && navigator.cookieEnabled);
|
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 = {}}) {
|
export function getMemberSubscription({member = {}}) {
|
||||||
if (isPaidMember({member})) {
|
if (isPaidMember({member})) {
|
||||||
const subscriptions = member.subscriptions || [];
|
const subscriptions = member.subscriptions || [];
|
||||||
|
|
Loading…
Add table
Reference in a new issue