Skip to content

Commit

Permalink
feat: Apply deny list to ajax metrics (#898)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Housley <[email protected]>
  • Loading branch information
Wrhector and patrickhousley authored Mar 8, 2024
1 parent bc5ebb5 commit a5c2adc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/features/ajax/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,30 @@ export class Aggregate extends AggregateBase {
hash = stringify([params.status, params.host, params.pathname])
}

const shouldCollect = shouldCollectEvent(params)
const ajaxMetricDenyListEnabled = agentInit.feature_flags?.includes('ajax_metrics_deny_list')

// store as metric
aggregator.store('xhr', hash, params, metrics)
if (shouldCollect || !ajaxMetricDenyListEnabled) {
aggregator.store('xhr', hash, params, metrics)
}

if (!allAjaxIsEnabled) return

if (!shouldCollectEvent(params)) {
if (!shouldCollect) {
if (params.hostname === beacon || (proxyBeacon && params.hostname === proxyBeacon)) {
// This doesn't make a distinction if the same-domain request is going to a different port or path...
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/Agent'], undefined, FEATURE_NAMES.metrics, ee)

if (ajaxMetricDenyListEnabled) {
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/Agent'], undefined, FEATURE_NAMES.metrics, ee)
}
} else {
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/App'], undefined, FEATURE_NAMES.metrics, ee)

if (ajaxMetricDenyListEnabled) {
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/App'], undefined, FEATURE_NAMES.metrics, ee)
}
}
return
}
Expand Down
24 changes: 24 additions & 0 deletions tests/specs/xhr/deny-list.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,28 @@ describe('xhr events deny list', () => {
: [])
]))
})

it('does not capture metrics when blocked and feature flag is enabled', async () => {
const [ajaxMetrics] = await Promise.all([
browser.testHandle.expectAjaxTimeSlices(10000, true),
browser.url(await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: true }, feature_flags: ['ajax_metrics_deny_list'] } }))
])

expect(ajaxMetrics).toBeUndefined()
})

it('captures metrics when feature flag is not present', async () => {
const [ajaxMetrics] = await Promise.all([
browser.testHandle.expectAjaxTimeSlices(),
browser.url(await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: true } } }))
])

expect(ajaxMetrics.request.body.xhr).toEqual(expect.arrayContaining([
expect.objectContaining({
params: expect.objectContaining({
hostname: browser.testHandle.bamServerConfig.host
})
})
]))
})
})

0 comments on commit a5c2adc

Please sign in to comment.