feat(web): apply RUM event mappers through beforeSend #1331
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 612 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.384
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1331"
general
weight: 0.35
fuzzybinary
What and why?
On Web, the RUM event mappers on
DatadogRumConfigurationare ignored:viewEventMapper,actionEventMapper,resourceEventMapper,errorEventMapperandlongTaskEventMapper. Apps can't redact or drop RUM events before they leave the browser. The plugin owns theDD_RUM.initcall, so an app can't add its ownbeforeSendeither.This PR applies those mappers through the Browser SDK's
beforeSend. Closes the RUM part of #1330; log mapping will follow in a separate PR.How?
RumWebEventMapper(new,datadog_flutter_plugin_web)beforeSendonly when at least one supported mapper is set. Without mappers,initoptions are unchanged.event.typefirst. Events of a type without a mapper returntrueand are never converted to Dart.1.
dartify()the event, build the existing Dart model withfromJson, and run the mapper.2. Copy back only the fields the Browser SDK keeps after
beforeSend(the allowlist inbrowser-rum-core/src/domain/assembly.ts): view name, URL and referrer;context; action target name; resource URL; error message, stack, fingerprint and resource URL.nullresult returnsfalse, which discards the event._dd.mapper_errorhandling.contextis converted before any field is written, so a failed conversion leaves the event untouched.vitalOperationStepEventMapperis not applied on Web and logs a warning (see below).Model defaults (
ddrum_events.dart)Events captured from Browser SDK 7.19
beforeSendare missing fields that the Dart models require, sofromJsonthrew for every browser event type. These@JsonKeydefaults fix that:view.crashdefaults to a count of 0.connectivity.interfacesdefaults to an empty list.resource.methoddefaults to'', since images and scripts have no method.serviceandversiondefault to''when unset.devicewithout atypereads asnull. Browser events only carry locale and time zone.Mobile always sends these fields, so its parsing is unchanged. The generated diff is limited to these fields.
Tests
rum_web_event_mapper_test.dart: 26 browser tests on JS and Wasm, using fixtures captured from the Browser SDK. They cover:- Each event type, read through identity mappers without changing it.
- Every field that is copied back.
- Discarding events.
- Unmapped types not being converted.
- Vital pass-through.
- Mapper exceptions, unreadable events and unconvertible context.
rum_mapping_test.dartis enabled for Web. Web adds an extra visit, as inrum_manual_test.dart, and also reports resources the browser loads, so view 1's resource assertion checks for the mapped URL instead of an exact count on Web.Performance
Measured in release builds of a benchmark app (Chrome 158, M-series Mac), per event, averaged over 5,000 events after warm-up:
| | dart2js | dart2wasm |
|---|---|---|
| Event type with a mapper (convert, map, write back) | 5–11 µs | 6–14 µs |
| Event type without a mapper | < 0.1 µs | < 0.3 µs |
| No mappers configured | no
beforeSend| nobeforeSend|dartify()was chosen overJSON.stringifyplusjsonDecode, which is 1.5–2× slower on Wasm. Example app bundle size grows by about 3.6 KB gzipped for dart2js (758.0 → 761.7 KB) and 3.4 KB for dart2wasm (797.1 → 800.5 KB).Not included
vitalOperationStepEventMapper. The Browser SDK omitsvital.failure_reasonon non-failure steps, butRumVital.failureReasonis a requiredString. A default would also be written back on mobile, so I left it for a separate change (details in #1330).Verification
melos run unit_test:web: all 44 web tests pass on JS and Wasm.melos run unit_test:flutter: the core, iOS, Android, desktop and example packages pass.datadog_tracking_http_clientanddatadog_webview_trackingfail dependency resolution ondevelopas well. They require core>=4.0.0-preview.2, but the core package in the repo is4.0.0-preview.1, so they're unrelated to this change.flutter drivewithrum_mapping_test.darton web-server/Chrome passes on JS and Wasm, against the local recording server with dummy credentials (no intake traffic).rum_manual_test.dartalso passes on Web as a regression check.dart format --set-exit-if-changedanddart analyzeare clean for the changed packages. Re-runningbuild_runnerleaves no diff.Review checklist
🤖 Generated with Claude Code