From 6b858b49038a032d7105f4fea16285e33a0cd3d4 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Thu, 9 Feb 2023 22:55:20 -0500 Subject: [PATCH] fix(replay): Fix missing fetch/xhr requests Logic was flipped for the filter function so fetch and xhr requests were not being recorded at all. --- .../replay/src/util/shouldFilterRequest.ts | 5 +++-- .../integration/shouldFilterRequest.test.ts | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 packages/replay/test/integration/shouldFilterRequest.test.ts diff --git a/packages/replay/src/util/shouldFilterRequest.ts b/packages/replay/src/util/shouldFilterRequest.ts index 07a4e94e6a16..7d66cf31d780 100644 --- a/packages/replay/src/util/shouldFilterRequest.ts +++ b/packages/replay/src/util/shouldFilterRequest.ts @@ -3,7 +3,8 @@ import { getCurrentHub } from '@sentry/core'; import type { ReplayContainer } from '../types'; /** - * Check whether a given request URL should be filtered out. + * Check whether a given request URL should be filtered out. This is so we + * don't log Sentry ingest requests. */ export function shouldFilterRequest(replay: ReplayContainer, url: string): boolean { // If we enabled the `traceInternals` experiment, we want to trace everything @@ -11,7 +12,7 @@ export function shouldFilterRequest(replay: ReplayContainer, url: string): boole return false; } - return !_isSentryRequest(url); + return _isSentryRequest(url); } /** diff --git a/packages/replay/test/integration/shouldFilterRequest.test.ts b/packages/replay/test/integration/shouldFilterRequest.test.ts new file mode 100644 index 000000000000..888b30e2c25f --- /dev/null +++ b/packages/replay/test/integration/shouldFilterRequest.test.ts @@ -0,0 +1,20 @@ +import { shouldFilterRequest } from '../../src/util/shouldFilterRequest'; +import { mockSdk } from '../index'; + +describe('Integration | shouldFilterRequest', () => { + beforeEach(() => { + jest.resetModules(); + }); + + it('should not filter requests from non-Sentry ingest URLs', async () => { + const { replay } = await mockSdk(); + + expect(shouldFilterRequest(replay, 'https://example.com/foo')).toBe(false); + }); + + it('should filter requests for Sentry ingest URLs', async () => { + const { replay } = await mockSdk(); + + expect(shouldFilterRequest(replay, 'https://03031aa.ingest.f00.f00/api/129312/')).toBe(true); + }); +});