Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dedup pre-load ajax requests #1081

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
Loading