Skip to content

Commit

Permalink
and like this
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 25, 2024
1 parent b85872c commit 2da2ec4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/__tests__/extensions/replay/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
9 changes: 8 additions & 1 deletion src/extensions/replay/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2da2ec4

Please sign in to comment.