Skip to content

Commit

Permalink
fix: dedup pre-load ajax requests (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhousley authored Jun 24, 2024
1 parent f5b9bc9 commit 9f95b33
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/common/deny-list/deny-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var denyList = []
* @returns {boolean} `true` if request does not match any entries of {@link denyList|deny list}; else `false`
*/
export function shouldCollectEvent (params) {
if (hasUndefinedHostname(params)) return false
if (!params || hasUndefinedHostname(params)) return false

if (denyList.length === 0) return true

Expand Down
8 changes: 4 additions & 4 deletions src/loaders/features/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const featurePriority = {
[FEATURE_NAMES.pageViewTiming]: 2,
[FEATURE_NAMES.metrics]: 3,
[FEATURE_NAMES.jserrors]: 4,
[FEATURE_NAMES.ajax]: 5,
[FEATURE_NAMES.sessionTrace]: 6,
[FEATURE_NAMES.pageAction]: 7,
[FEATURE_NAMES.spa]: 8,
[FEATURE_NAMES.spa]: 5,
[FEATURE_NAMES.ajax]: 6,
[FEATURE_NAMES.sessionTrace]: 7,
[FEATURE_NAMES.pageAction]: 8,
[FEATURE_NAMES.softNav]: 9,
[FEATURE_NAMES.sessionReplay]: 10,
[FEATURE_NAMES.logging]: 11
Expand Down
19 changes: 19 additions & 0 deletions tests/specs/spa/fetch.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,23 @@ describe.withBrowsersMatching(supportsFetch)('Fetch SPA Interaction Tracking', (
const ajaxEvent = interactionEventsHarvest.request.body[0].children.find(event => event.path === '/paththatdoesnotexist')
expect(ajaxEvent.status).toEqual(404)
})

it('only captures pre-load ajax calls in the spa payload', async () => {
const [interactionResults, eventsResults] = await Promise.all([
browser.testHandle.expectInteractionEvents(),
browser.testHandle.expectAjaxEvents(),
browser.url(await browser.testHandle.assetURL('ajax/fetch-before-load.html'))
.then(() => browser.waitForAgentLoad())
])

const spaAjaxCalls = interactionResults.request.body[0].children.filter(xhr =>
xhr.type === 'ajax' && xhr.path === '/json'
)
expect(spaAjaxCalls.length).toEqual(1)

const eventsAjaxCalls = eventsResults.request.body.filter(xhr =>
xhr.type === 'ajax' && xhr.path === '/json'
)
expect(eventsAjaxCalls.length).toEqual(0)
})
})
33 changes: 19 additions & 14 deletions tests/specs/spa/xhr.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,6 @@ describe('XHR SPA Interaction Tracking', () => {
expect(ajaxEvent.status).toEqual(0)
})

// TODO: This test should pass but the agent contains a bug https://new-relic.atlassian.net/browse/NR-270107
// it('produces interaction event data when xhr has bad 3rd party wrapping after agent', async () => {
// await browser.url(await browser.testHandle.assetURL('ajax/xhr-bad-wrapper-after.html'))
// .then(() => browser.waitForAgentLoad())
//
// const [interactionResults] = await Promise.all([
// browser.testHandle.expectInteractionEvents(),
// $('#sendAjax').click()
// ])
//
// checkSpa(interactionResults.request, { trigger: 'click' })
// checkAjaxEvents({ body: interactionResults.request.body[0].children, query: interactionResults.request.query }, { specificPath: '/json' })
// })

it('produces interaction event data when xhr is 3rd party listener patched after agent', async () => {
await browser.url(await browser.testHandle.assetURL('ajax/xhr-patch-listener-after.html'))
.then(() => browser.waitForAgentLoad())
Expand Down Expand Up @@ -366,4 +352,23 @@ describe('XHR SPA Interaction Tracking', () => {
)
expect(timers.length).toEqual(2)
})

it('only captures pre-load ajax calls in the spa payload', async () => {
const [interactionResults, eventsResults] = await Promise.all([
browser.testHandle.expectInteractionEvents(),
browser.testHandle.expectAjaxEvents(),
browser.url(await browser.testHandle.assetURL('ajax/xhr-before-load.html'))
.then(() => browser.waitForAgentLoad())
])

const spaAjaxCalls = interactionResults.request.body[0].children.filter(xhr =>
xhr.type === 'ajax' && xhr.path === '/json'
)
expect(spaAjaxCalls.length).toEqual(1)

const eventsAjaxCalls = eventsResults.request.body.filter(xhr =>
xhr.type === 'ajax' && xhr.path === '/json'
)
expect(eventsAjaxCalls.length).toEqual(0)
})
})

0 comments on commit 9f95b33

Please sign in to comment.