Skip to content

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

Draft
thomasbertet wants to merge 6 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 6 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 (Blog post) experimental Browser API (currently available in Edge 146+ and Chromium behind the --enable-features=DocumentPolicyNetworkEfficiencyGuardrails flag), and more broadly, all current and future document-policy-violation reports.

When a page opts in via a Document-Policy header (e.g. Document-Policy: network-efficiency-guardrails), the browser fires document-policy-violation reports for resources that violate the policy. This change collects those reports as SDK errors/logs, following the same pattern as csp_violation, intervention, and deprecation. Rather than filtering to a specific featureId, the SDK forwards all document-policy-violation reports — so any current or future document policy feature is automatically captured without further SDK changes.

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.documentPolicyViolation = document-policy-violation; buildRawReportErrorFromReport() handles the new type (reuses csp.disposition field for disposition, uses featureId as the error type).
  • browser-rum-coretrackReportError.ts: Added documentPolicyViolation to the subscribed report types so RUM collects these as errors automatically.
  • browser-core testsmockReportingObserver.ts: Added FAKE_DOCUMENT_POLICY_VIOLATION_REPORT fixture. reportObservable.spec.ts: 3 new unit tests (notification, stack trace, any-featureId passthrough).
  • E2Emock.ts: Added /?network-efficiency-guardrails=true query param (sets Document-Policy: network-efficiency-guardrails header) and /uncompressed-script.js endpoint. networkEfficiencyGuardrails.scenario.ts: 3 new E2E tests (RUM errors, Logs forwarding with forwardReports: ["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 the chromium project):

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

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

DataDog/browser-sdk | unit   View in Datadog   GitLab

🧪 17 Tests failed

console collection console error should have an error object defined from Chrome Headless 149.0.0.0 (Linux 0.0.0)   View in Datadog
Expected object not to have properties
    feature_id: undefined
Error: Expected object not to have properties
    feature_id: undefined
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/browser-logs/src/domain/console/consoleCollection.spec.ts:118:49 <- /tmp/_karma_webpack_162897/commons.js:388779:53)
    at <Jasmine>
Logger error handling in logImplementation should compute stackTrace when error is an instance of Error from Chrome Headless 149.0.0.0 (Linux 0.0.0)   View in Datadog
Expected object not to have properties
    feature_id: undefined
Error: Expected object not to have properties
    feature_id: undefined
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/browser-logs/src/domain/logger.spec.ts:326:27 <- /tmp/_karma_webpack_162897/commons.js:389406:33)
    at <Jasmine>
View all 17 test failures

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 91.67%
Overall Coverage: 76.80% (-0.19%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c61b11a | 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.35 KiB +316 B +0.18%
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.51 KiB +304 B +0.55%
Rum Slim 129.72 KiB 130.02 KiB +310 B +0.23%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%


/**
* Maps internal RawReportType values to the browser ReportingObserver type strings.
* `network-efficiency-guardrails` is exposed via `document-policy-violation` reports,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we report all (and future) document-policy-violation instead of focusing on network-efficiency-guardrails?

@thomasbertet thomasbertet Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@thomasbertet thomasbertet force-pushed the thomas.bertet/PROF-15113-add-network-guardrails-to-sdk branch from 8bae3c1 to 53d0071 Compare June 24, 2026 12:36
message: `${type}: ${body.message}`,
originalError: report,
stack: buildStack(body.id, body.message, body.sourceFile, body.lineNumber, body.columnNumber),
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@thomasbertet thomasbertet Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
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.

2 participants