Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions static/app/bootstrap/initializeSdk.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,54 @@ describe('initializeSdk', () => {
})
);
});

describe('beforeSend', () => {
const initAndGetBeforeSend = () => {
initializeSdk({
...window.__initialData,
distPrefix: 'https://s1.sentry-cdn.com/_static/dist/sentry/',
sentryConfig: {
allowUrls: [],
dsn: '',
release: '',
tracePropagationTargets: [],
},
});

const [options] = jest.mocked(Sentry.init).mock.calls.at(-1)!;

return options.beforeSend!;
};

const eventFromFrames = (...filenames: string[]) => ({
type: undefined,
exception: {
values: [{stacktrace: {frames: filenames.map(filename => ({filename}))}}],
},
});

it('drops an event whose frames are all third-party', () => {
const beforeSend = initAndGetBeforeSend();

const result = beforeSend(
eventFromFrames(`${window.location.origin}/issues/`, '<anonymous>'),
{}
);

expect(result).toBeNull();
});

it('keeps an event with a frame from our assets', () => {
const beforeSend = initAndGetBeforeSend();
const event = eventFromFrames(
'https://s1.sentry-cdn.com/_static/dist/sentry/chunks/56177.cad95fee92a5a772.js'
);

const result = beforeSend(event, {});

expect(result).toBe(event);
});
});
});

describe('isFilteredRequestErrorEvent', () => {
Expand Down
11 changes: 9 additions & 2 deletions static/app/bootstrap/initializeSdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type {Config} from 'sentry/types/system';
import {addUIElementTagToSegmentSpan} from 'sentry/utils/performanceForSentry';
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';

import {getFirstPartyOrigins, isThirdPartyScriptEvent} from './thirdPartyScriptFilter';

let lastEventId: string | undefined;

export function getLastEventId(): string | undefined {
Expand Down Expand Up @@ -91,11 +93,12 @@ function getSentryIntegrations() {
*/
export function initializeSdk(config: Config) {
// NOTE: This config is mutated by `commonInitialization`
const {apmSampling, customerDomain, sentryConfig, userIdentity} = config;
const {apmSampling, customerDomain, distPrefix, sentryConfig, userIdentity} = config;
const tracesSampleRate = apmSampling ?? 0;
const extraTracePropagationTargets = SPA_DSN
? SPA_MODE_TRACE_PROPAGATION_TARGETS
: [...sentryConfig.tracePropagationTargets];
const firstPartyOrigins = getFirstPartyOrigins(distPrefix);

const sentryClient = Sentry.init({
...sentryConfig,
Expand Down Expand Up @@ -182,7 +185,11 @@ export function initializeSdk(config: Config) {
},

beforeSend(event, hint) {
if (isFilteredRequestErrorEvent(event) || isEventWithFileUrl(event)) {
if (
isFilteredRequestErrorEvent(event) ||
isEventWithFileUrl(event) ||
isThirdPartyScriptEvent(event, firstPartyOrigins)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We gotta call out the difference between the new code and thirdPartyErrorFilterIntegration

) {
return null;
}

Expand Down
Loading
Loading