← Back to Pull requests

feat(web): apply RUM event mappers through beforeSend #1331

Open
unknown opened this pull request with 612 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 29, 2026 11:41 UTC
Author

What and why?

On Web, the RUM event mappers on DatadogRumConfiguration are ignored: viewEventMapper, actionEventMapper, resourceEventMapper, errorEventMapper and longTaskEventMapper. Apps can't redact or drop RUM events before they leave the browser. The plugin owns the DD_RUM.init call, so an app can't add its own beforeSend either.

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)

  • Registered as beforeSend only when at least one supported mapper is set. Without mappers, init options are unchanged.

  • Reads event.type first. Events of a type without a mapper return true and are never converted to Dart.

  • For mapped types:

  • 1. dartify() the event, build the existing Dart model with fromJson, and run the mapper.
    2. Copy back only the fields the Browser SDK keeps after beforeSend (the allowlist in browser-rum-core/src/domain/assembly.ts): view name, URL and referrer; context; action target name; resource URL; error message, stack, fingerprint and resource URL.
  • A null result returns false, which discards the event.

  • If a mapper throws, or an event can't be read, the event is sent unmapped and the error is logged once per event type. This matches iOS's _dd.mapper_error handling.

  • context is converted before any field is written, so a failed conversion leaves the event untouched.

  • vitalOperationStepEventMapper is not applied on Web and logs a warning (see below).
  • Model defaults (ddrum_events.dart)

    Events captured from Browser SDK 7.19 beforeSend are missing fields that the Dart models require, so fromJson threw for every browser event type. These @JsonKey defaults fix that:

  • view.crash defaults to a count of 0.

  • connectivity.interfaces defaults to an empty list.

  • resource.method defaults to '', since images and scripts have no method.

  • View service and version default to '' when unset.

  • A device without a type reads as null. 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.
  • With the old generated parser, 18 of the 26 tests fail.

  • rum_mapping_test.dart is enabled for Web. Web adds an extra visit, as in rum_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 | no beforeSend |

    dartify() was chosen over JSON.stringify plus jsonDecode, 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

  • Log mapping, which will be a follow-up PR.

  • vitalOperationStepEventMapper. The Browser SDK omits vital.failure_reason on non-failure steps, but RumVital.failureReason is a required String. 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_client and datadog_webview_tracking fail dependency resolution on develop as well. They require core >=4.0.0-preview.2, but the core package in the repo is 4.0.0-preview.1, so they're unrelated to this change.

  • flutter drive with rum_mapping_test.dart on web-server/Chrome passes on JS and Wasm, against the local recording server with dummy credentials (no intake traffic). rum_manual_test.dart also passes on Web as a regression check.

  • dart format --set-exit-if-changed and dart analyze are clean for the changed packages. Re-running build_runner leaves no diff.
  • Review checklist

  • This pull request has appropriate unit and / or integration tests

  • This pull request references a Github or JIRA issue
  • 🤖 Generated with Claude Code

    Diff: 612 lines (+459 / -153) across 7 files Reviewer: fuzzybinary Review duration: 2607m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.2% (MEDIUM) · Higher = larger blast radius
    50.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.8% · Safe to merge
    26.8%