Skip to content

Commit 53d0071

Browse files
committed
♻️ generalise document-policy-violation support to all featureIds
Replace the NEG-specific `networkEfficiencyGuardrails` RawReportType with a generic `documentPolicyViolation: 'document-policy-violation'` entry that mirrors how `intervention` and `deprecation` are modelled. - Remove the `buildReportObserverTypes()` mapping layer (it existed solely to translate 'network-efficiency-guardrails' → 'document-policy-violation') - Remove the featureId filter in the ReportingObserver callback that was silently dropping non-NEG document-policy-violation reports - RUM now collects all document-policy-violation reports automatically; Logs users opt in with `forwardReports: ['document-policy-violation']` - Future document policy features (e.g. js-profiling-mode, sync-xhr) are automatically captured without any SDK change
1 parent 9df763e commit 53d0071

4 files changed

Lines changed: 17 additions & 44 deletions

File tree

packages/browser-core/src/domain/report/reportObservable.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ describe('report observable', () => {
8080
expect(notifyReport).not.toHaveBeenCalled()
8181
})
8282

83-
it(`should notify ${RawReportType.networkEfficiencyGuardrails} reports`, () => {
84-
consoleSubscription = initReportObservable([RawReportType.networkEfficiencyGuardrails]).subscribe(notifyReport)
83+
it(`should notify ${RawReportType.documentPolicyViolation} reports`, () => {
84+
consoleSubscription = initReportObservable([RawReportType.documentPolicyViolation]).subscribe(notifyReport)
8585
reportingObserver.raiseReport('document-policy-violation')
8686

8787
expect(notifyReport).toHaveBeenCalledOnceWith(
@@ -93,8 +93,8 @@ describe('report observable', () => {
9393
)
9494
})
9595

96-
it(`should compute stack for ${RawReportType.networkEfficiencyGuardrails}`, () => {
97-
consoleSubscription = initReportObservable([RawReportType.networkEfficiencyGuardrails]).subscribe(notifyReport)
96+
it(`should compute stack for ${RawReportType.documentPolicyViolation}`, () => {
97+
consoleSubscription = initReportObservable([RawReportType.documentPolicyViolation]).subscribe(notifyReport)
9898
reportingObserver.raiseReport('document-policy-violation')
9999

100100
const [report] = notifyReport.calls.mostRecent().args
@@ -104,12 +104,16 @@ describe('report observable', () => {
104104
at <anonymous> @ https://foo.bar/large-uncompressed.js`)
105105
})
106106

107-
it(`should not notify document-policy-violation reports with a featureId other than ${RawReportType.networkEfficiencyGuardrails}`, () => {
108-
consoleSubscription = initReportObservable([RawReportType.networkEfficiencyGuardrails]).subscribe(notifyReport)
107+
it(`should notify ${RawReportType.documentPolicyViolation} reports regardless of featureId`, () => {
108+
consoleSubscription = initReportObservable([RawReportType.documentPolicyViolation]).subscribe(notifyReport)
109109
reportingObserver.raiseReport('document-policy-violation', {
110110
body: { ...FAKE_DOCUMENT_POLICY_VIOLATION_REPORT.body, featureId: 'some-other-policy' },
111111
})
112112

113-
expect(notifyReport).not.toHaveBeenCalled()
113+
expect(notifyReport).toHaveBeenCalledOnceWith(
114+
jasmine.objectContaining({
115+
type: 'some-other-policy',
116+
})
117+
)
114118
})
115119
})

packages/browser-core/src/domain/report/reportObservable.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const RawReportType = {
1212
intervention: 'intervention',
1313
deprecation: 'deprecation',
1414
cspViolation: 'csp_violation',
15-
networkEfficiencyGuardrails: 'network-efficiency-guardrails',
15+
documentPolicyViolation: 'document-policy-violation',
1616
} as const
1717

1818
export type RawReportType = (typeof RawReportType)[keyof typeof RawReportType]
@@ -28,34 +28,14 @@ export function initReportObservable(apis: RawReportType[]) {
2828
observables.push(createCspViolationReportObservable())
2929
}
3030

31-
const reportTypes = buildReportObserverTypes(apis)
31+
const reportTypes = apis.filter((api): api is ReportType => api !== RawReportType.cspViolation)
3232
if (reportTypes.length) {
3333
observables.push(createReportObservable(reportTypes))
3434
}
3535

3636
return mergeObservables(...observables)
3737
}
3838

39-
/**
40-
* Maps internal RawReportType values to the browser ReportingObserver type strings.
41-
* `network-efficiency-guardrails` is exposed via `document-policy-violation` reports,
42-
* filtered by `body.featureId === 'network-efficiency-guardrails'`.
43-
*/
44-
function buildReportObserverTypes(apis: RawReportType[]): ReportType[] {
45-
const types = new Set<ReportType>()
46-
for (const api of apis) {
47-
if (api === RawReportType.cspViolation) {
48-
continue
49-
}
50-
if (api === RawReportType.networkEfficiencyGuardrails) {
51-
types.add('document-policy-violation')
52-
} else {
53-
types.add(api)
54-
}
55-
}
56-
return Array.from(types)
57-
}
58-
5939
function createReportObservable(reportTypes: ReportType[]) {
6040
return new Observable<RawReportError>((observable) => {
6141
if (!window.ReportingObserver) {
@@ -64,18 +44,7 @@ function createReportObservable(reportTypes: ReportType[]) {
6444

6545
const handleReports = monitor(
6646
(reports: Array<DeprecationReport | InterventionReport | DocumentPolicyViolationReport>, _: ReportingObserver) =>
67-
reports.forEach((report) => {
68-
// document-policy-violation reports are only subscribed to when
69-
// network-efficiency-guardrails is requested. Skip any document policy violation
70-
// whose featureId does not match network-efficiency-guardrails.
71-
if (
72-
report.type === 'document-policy-violation' &&
73-
report.body.featureId !== RawReportType.networkEfficiencyGuardrails
74-
) {
75-
return
76-
}
77-
observable.notify(buildRawReportErrorFromReport(report))
78-
})
47+
reports.forEach((report) => observable.notify(buildRawReportErrorFromReport(report)))
7948
) as ReportingObserverCallback
8049

8150
const observer = new window.ReportingObserver(handleReports, {

packages/browser-rum-core/src/domain/error/trackReportError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function trackReportError(errorObservable: Observable<RawError>) {
44
const subscription = initReportObservable([
55
RawReportType.cspViolation,
66
RawReportType.intervention,
7-
RawReportType.networkEfficiencyGuardrails,
7+
RawReportType.documentPolicyViolation,
88
]).subscribe((rawError) => errorObservable.notify(rawError))
99

1010
return {

test/e2e/scenario/networkEfficiencyGuardrails.scenario.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test.describe('network efficiency guardrails', () => {
5454

5555
test.describe('Logs', () => {
5656
createTest('should forward network-efficiency-guardrails violations via forwardReports')
57-
.withLogs({ forwardReports: ['network-efficiency-guardrails'] })
57+
.withLogs({ forwardReports: ['document-policy-violation'] })
5858
.withBasePath('/?network-efficiency-guardrails=true')
5959
.run(async ({ page, intakeRegistry, flushEvents, withBrowserLogs }) => {
6060
await page.evaluate(() => fetch('/uncompressed-script.js'))
@@ -75,7 +75,7 @@ test.describe('network efficiency guardrails', () => {
7575
})
7676
})
7777

78-
createTest('should not forward network-efficiency-guardrails violations when not in forwardReports')
78+
createTest('should not forward network-efficiency-guardrails violations when not opted in')
7979
.withLogs({ forwardReports: [] })
8080
.withBasePath('/?network-efficiency-guardrails=true')
8181
.run(async ({ page, intakeRegistry, flushEvents, withBrowserLogs }) => {

0 commit comments

Comments
 (0)