Skip to content

Commit

Permalink
ah, much nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 25, 2024
1 parent 2c959f0 commit b85872c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
17 changes: 15 additions & 2 deletions src/__tests__/extensions/replay/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,47 @@ describe('config', () => {
{
name: 'https://app.posthog.com/api/feature_flag/',
},
undefined,
],
[
{
name: 'https://app.posthog.com/s/?ip=1&ver=123',
},
undefined,
undefined,
],
[
{
name: 'https://app.posthog.com/e/?ip=1&ver=123',
},
undefined,
undefined,
],
[
{
name: 'https://app.posthog.com/i/v0/e/?ip=1&ver=123',
},
undefined,
undefined,
],
[
{
// even an imaginary future world of rust session replay capture
name: 'https://app.posthog.com/i/v0/s/?ip=1&ver=123',
},
undefined,
undefined,
],
])('ignores ingestion paths', (capturedRequest, expected) => {
const networkOptions = buildNetworkRequestOptions(defaultConfig(), {})
[
{
// even an imaginary future world of rust session replay capture
name: 'https://app.posthog.com/ingest/s/?ip=1&ver=123',
},
undefined,
'/ingest',
],
])('ignores ingestion paths', (capturedRequest, expected, apiHost?: string) => {
const networkOptions = buildNetworkRequestOptions({ ...defaultConfig(), api_host: apiHost }, {})
const x = networkOptions.maskRequestFn!(capturedRequest as CapturedNetworkRequest)
expect(x).toEqual(expected)
})
Expand Down
18 changes: 7 additions & 11 deletions src/extensions/replay/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ const removeAuthorizationHeader = (data: CapturedNetworkRequest): CapturedNetwor
const POSTHOG_PATHS_TO_IGNORE = ['/s/', '/e/', '/i/']
// want to ignore posthog paths when capturing requests, or we can get trapped in a loop
// because calls to PostHog would be reported using a call to PostHog which would be reported....
const ignorePostHogPaths = (data: CapturedNetworkRequest): CapturedNetworkRequest | undefined => {
const ignorePostHogPaths = (
data: CapturedNetworkRequest,
apiHostConfig: PostHogConfig['api_host']
): CapturedNetworkRequest | undefined => {
const url = convertToURL(data.name)
if (
url &&
url.pathname &&
// matches our `/s/` path but also paths within a reverse proxy like `/ingest/s/`
POSTHOG_PATHS_TO_IGNORE.some((path) => url.pathname.indexOf(path) >= 0) &&
// since we're matching `/blah/` loosely, also check a couple of the query params we add
url.search.indexOf('ver=') >= 0 &&
url.search.indexOf('ip=') >= 0
) {
const pathname = url?.pathname.replace(apiHostConfig, '')
if (url && pathname && POSTHOG_PATHS_TO_IGNORE.some((path) => pathname.indexOf(path) === 0)) {
return undefined
}
return data
Expand Down Expand Up @@ -219,7 +215,7 @@ export const buildNetworkRequestOptions = (
const payloadLimiter = limitPayloadSize(config)

const enforcedCleaningFn: NetworkRecordOptions['maskRequestFn'] = (d: CapturedNetworkRequest) =>
payloadLimiter(ignorePostHogPaths(removeAuthorizationHeader(d)))
payloadLimiter(ignorePostHogPaths(removeAuthorizationHeader(d), instanceConfig.api_host))

const hasDeprecatedMaskFunction = isFunction(instanceConfig.session_recording.maskNetworkRequestFn)

Expand Down

0 comments on commit b85872c

Please sign in to comment.