Skip to content

⚗️ collect Network Efficiency Guardrails document-policy-violation reports as errors#4796

Draft
thomasbertet wants to merge 4 commits into
mainfrom
thomas.bertet/PROF-15113-add-network-guardrails-to-sdk
Draft

⚗️ collect Network Efficiency Guardrails document-policy-violation reports as errors#4796
thomasbertet wants to merge 4 commits into
mainfrom
thomas.bertet/PROF-15113-add-network-guardrails-to-sdk

Conversation

@thomasbertet

@thomasbertet thomasbertet commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Add support for the Network Efficiency Guardrails experimental browser API (currently available in Edge 146+ and Chromium behind the --enable-experimental-web-platform-features flag).

When a page opts in via the Document-Policy: network-efficiency-guardrails header, the browser fires document-policy-violation reports for resources that violate the policy (e.g. uncompressed JS/CSS). This change collects those reports as SDK errors/logs, following the same pattern as csp_violation, intervention, and deprecation.

Jira: PROF-15113

Changes

  • browser-corebrowser.types.ts: Added DocumentPolicyViolationReport and DocumentPolicyViolationReportBody interfaces; widened Report.body union and ReportType union.
  • browser-corereportObservable.ts: Added RawReportType.networkEfficiencyGuardrails = 'network-efficiency-guardrails'; buildReportObserverTypes() maps it to the document-policy-violation ReportingObserver type; buildRawReportErrorFromReport() handles the new type (filters to NEG featureId, reuses csp.disposition field).
  • browser-rum-coretrackReportError.ts: Added networkEfficiencyGuardrails to the subscribed report types so RUM collects these as errors.
  • browser-core testsmockReportingObserver.ts: Added FAKE_DOCUMENT_POLICY_VIOLATION_REPORT fixture. reportObservable.spec.ts: 3 new unit tests (notification, stack trace, featureId filter).
  • E2Emock.ts: Added /?network-efficiency-guardrails=true query param (sets Document-Policy header) and /uncompressed-script.js endpoint. networkEfficiencyGuardrails.scenario.ts: 3 new E2E tests (RUM errors, Logs forwarding ON, Logs forwarding OFF).

Test instructions

E2E tests require Chromium with --enable-experimental-web-platform-features (handled automatically by test.use({ launchOptions }) in the scenario file):

yarn build
yarn test:e2e -g "network efficiency"

Unit tests:

yarn test:unit --spec packages/browser-core/src/domain/report/reportObservable.spec.ts

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jun 17, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 82.61%
Overall Coverage: 76.80% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9df763e | Docs | Datadog PR Page | Give us feedback!

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 17, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.04 KiB 172.45 KiB +424 B +0.24%
Rum Profiler 8.01 KiB 8.01 KiB 0 B 0.00%
Rum Recorder 21.09 KiB 21.09 KiB 0 B 0.00%
Logs 54.21 KiB 54.70 KiB +502 B +0.90%
Rum Slim 129.72 KiB 130.13 KiB +424 B +0.32%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant