⚗️ collect Network Efficiency Guardrails document-policy-violation reports as errors#4796
⚗️ collect Network Efficiency Guardrails document-policy-violation reports as errors#4796thomasbertet wants to merge 6 commits into
Conversation
|
Bundles Sizes Evolution
|
|
|
||
| /** | ||
| * Maps internal RawReportType values to the browser ReportingObserver type strings. | ||
| * `network-efficiency-guardrails` is exposed via `document-policy-violation` reports, |
There was a problem hiding this comment.
question: can we report all (and future) document-policy-violation instead of focusing on network-efficiency-guardrails?
There was a problem hiding this comment.
It seems pretty doable, would you rather support all of them ? It may even be less code actually :)
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
8bae3c1 to
53d0071
Compare
| message: `${type}: ${body.message}`, | ||
| originalError: report, | ||
| stack: buildStack(body.id, body.message, body.sourceFile, body.lineNumber, body.columnNumber), | ||
| }) |
There was a problem hiding this comment.
suggestion: why not stick with the DOM model here, and set type: 'document-policy-violation' and introduce a new field feature_id: 'network-efficiency-guardrails' or something? So we can refactor code and customers can refer to the MDN docs to understand the data model
There was a problem hiding this comment.
Makes sense indeed! It would need a rum-event-types update though to support the new featureId field.
Set `error.type` to `'document-policy-violation'` (the report type, matching the DOM/spec model) and expose `featureId` (e.g. `'network-efficiency-guardrails'`) as a dedicated top-level field on the error, following the spec's naming for DocumentPolicyViolationReportBody.featureId. - RawError gets a new optional `featureId` field - Forwarded as `feature_id` in RUM (via combine(), pending rum-events-format schema update) - Forwarded as `feature_id` in Logs (rawLogsEvent Error interface) - intervention/deprecation reports are unchanged (they use body.id as type)
Motivation
Add support for the Network Efficiency Guardrails (Blog post) experimental Browser API (currently available in Edge 146+ and Chromium behind the
--enable-features=DocumentPolicyNetworkEfficiencyGuardrailsflag), and more broadly, all current and futuredocument-policy-violationreports.When a page opts in via a
Document-Policyheader (e.g.Document-Policy: network-efficiency-guardrails), the browser firesdocument-policy-violationreports for resources that violate the policy. This change collects those reports as SDK errors/logs, following the same pattern ascsp_violation,intervention, anddeprecation. Rather than filtering to a specificfeatureId, the SDK forwards alldocument-policy-violationreports — so any current or future document policy feature is automatically captured without further SDK changes.Jira: PROF-15113
Changes
browser-core—browser.types.ts: AddedDocumentPolicyViolationReportandDocumentPolicyViolationReportBodyinterfaces; widenedReport.bodyunion andReportTypeunion.browser-core—reportObservable.ts: AddedRawReportType.documentPolicyViolation = document-policy-violation;buildRawReportErrorFromReport()handles the new type (reusescsp.dispositionfield fordisposition, usesfeatureIdas the errortype).browser-rum-core—trackReportError.ts: AddeddocumentPolicyViolationto the subscribed report types so RUM collects these as errors automatically.browser-coretests —mockReportingObserver.ts: AddedFAKE_DOCUMENT_POLICY_VIOLATION_REPORTfixture.reportObservable.spec.ts: 3 new unit tests (notification, stack trace, any-featureId passthrough).mock.ts: Added/?network-efficiency-guardrails=truequery param (setsDocument-Policy: network-efficiency-guardrailsheader) and/uncompressed-script.jsendpoint.networkEfficiencyGuardrails.scenario.ts: 3 new E2E tests (RUM errors, Logs forwarding withforwardReports: ["document-policy-violation"], Logs not forwarding when not opted in).Test instructions
E2E tests require Chromium with
--enable-features=DocumentPolicyNetworkEfficiencyGuardrails(handled automatically by the Playwright config for thechromiumproject):yarn build yarn test:e2e -g "network efficiency"Unit tests:
Checklist