From 2da2ec44dcf3a1b2fdd1ff66fcbff49231c27ae9 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 25 Nov 2024 23:43:47 +0000 Subject: [PATCH] and like this --- src/__tests__/extensions/replay/config.test.ts | 13 ++++++++++++- src/extensions/replay/config.ts | 9 ++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/__tests__/extensions/replay/config.test.ts b/src/__tests__/extensions/replay/config.test.ts index 6ef2d93f9..be0b96c0d 100644 --- a/src/__tests__/extensions/replay/config.test.ts +++ b/src/__tests__/extensions/replay/config.test.ts @@ -114,8 +114,19 @@ describe('config', () => { undefined, '/ingest', ], + [ + { + // even an imaginary future world of rust session replay capture + name: 'https://app.posthog.com/ingest/s/?ip=1&ver=123', + }, + undefined, + 'https://app.posthog.com/ingest', + ], ])('ignores ingestion paths', (capturedRequest, expected, apiHost?: string) => { - const networkOptions = buildNetworkRequestOptions({ ...defaultConfig(), api_host: apiHost }, {}) + const networkOptions = buildNetworkRequestOptions( + { ...defaultConfig(), api_host: apiHost || 'https://us.posthog.com' }, + {} + ) const x = networkOptions.maskRequestFn!(capturedRequest as CapturedNetworkRequest) expect(x).toEqual(expected) }) diff --git a/src/extensions/replay/config.ts b/src/extensions/replay/config.ts index 7f021ffd1..d4bc96c4f 100644 --- a/src/extensions/replay/config.ts +++ b/src/extensions/replay/config.ts @@ -101,7 +101,14 @@ const ignorePostHogPaths = ( apiHostConfig: PostHogConfig['api_host'] ): CapturedNetworkRequest | undefined => { const url = convertToURL(data.name) - const pathname = url?.pathname.replace(apiHostConfig, '') + + // we need to account for api host config as e.g. pathname could be /ingest/s/ and we want to ignore that + let replaceValue = apiHostConfig.indexOf('http') === 0 ? convertToURL(apiHostConfig)?.pathname : apiHostConfig + if (replaceValue === '/') { + replaceValue = '' + } + const pathname = url?.pathname.replace(replaceValue || '', '') + if (url && pathname && POSTHOG_PATHS_TO_IGNORE.some((path) => pathname.indexOf(path) === 0)) { return undefined }