Article

Keep personal data out of RUM and logs

Find where email addresses leak into Datadog RUM, logs and session replay, scrub them before they leave the browser and check that the fix works.

Published Updated 10 min read

Frontend telemetry often collects more than you expect. One URL with an email address in its query string can end up in RUM views, in browser logs and in APM spans, and Datadog then keeps it for weeks. This guide shows where personal data leaks into Datadog RUM, logs and session replay, how to remove it before it leaves the browser or your servers, and how to check the fix. It is written for frontend tech leads and platform engineers who own a Datadog setup. The examples use @datadog/browser-rum 7.19.0 and @datadog/browser-logs 7.19.0, the current versions on 1 December 2026.

Find where personal data leaks in

Datadog describes RUM privacy as a shared responsibility: Datadog gives you the controls, and you decide what the SDK collects. By default, the SDK does not track user identity. Most leaks come from URLs, messages and labels that your own app creates.

Location Example Where to fix it
view.url, view.referrer /account/reset?email=jane%40example.com RUM beforeSend or manual view names
resource.url, error.resource.url /api/orders?email=jane%40example.com RUM beforeSend
error.message, error.stack No customer found for jane@example.com RUM and Logs beforeSend
action.target.name A button that shows the email of the user Action name privacy, data-dd-action-name
usr.* setUser with an email address Do not send it
Browser logs view.url, message The same URL, added to every log Logs beforeSend
APM http.url The full URL of a server request Tracer and Agent obfuscation
Server logs An access log line with the query string Agent mask_sequences rules
Session replay Text on the page and in form fields Replay privacy level

Check this before you change anything, because the fix is different for each location. Datadog keeps RUM sessions, views, actions, errors and replays for 30 days, and resources and long tasks for 15 days. So a leak that you find today can still be in the data a month later.

Scrub URLs in the RUM beforeSend callback

The browser RUM SDK calls beforeSend for every event before it sends the event. In the callback, you can change some properties, add context, or return false to discard the event. You cannot discard view events.

You can change only the properties on the Datadog list. For personal data, these are the important ones:

  • view.url, view.referrer and view.name
  • resource.url and error.resource.url
  • error.message and error.stack
  • action.target.name
  • context

The SDK ignores changes to other properties. Put the scrub logic in one shared function, so that RUM and logs use the same rules:

// telemetry-scrub.ts
const EMAIL = /[A-Za-z0-9._%+-]+(?:@|%40)[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
const SENSITIVE_PARAM = /([?&#](?:email|token)=)[^&#]*/gi;

export function scrub(value: string): string {
  return value.replace(SENSITIVE_PARAM, '$1REDACTED').replace(EMAIL, 'REDACTED_EMAIL');
}

The email pattern also matches %40, because a browser encodes @ in a query string. Change the parameter names to the ones that your app uses.

Then call the function in beforeSend:

import { datadogRum } from '@datadog/browser-rum';
import { scrub } from './telemetry-scrub';

datadogRum.init({
  applicationId: '<application-id>',
  clientToken: '<client-token>',
  site: '<site>',
  service: '<service>',
  env: '<env>',
  version: '<version>',
  sessionSampleRate: 100,
  sessionReplaySampleRate: 5,
  defaultPrivacyLevel: 'mask',
  enablePrivacyForActionName: true,
  beforeSend: (event) => {
    if (event.view) {
      event.view.url = scrub(event.view.url);
      if (event.view.referrer) event.view.referrer = scrub(event.view.referrer);
      if (event.view.name) event.view.name = scrub(event.view.name);
    }
    if (event.type === 'resource') {
      event.resource.url = scrub(event.resource.url);
    }
    if (event.type === 'error') {
      event.error.message = scrub(event.error.message);
      if (event.error.stack) event.error.stack = scrub(event.error.stack);
      if (event.error.resource) event.error.resource.url = scrub(event.error.resource.url);
    }
    if (event.type === 'action' && event.action.target) {
      event.action.target.name = scrub(event.action.target.name);
    }
    return true;
  },
});

Note these points:

  • The SDK sends a view event several times while the view is active. Derive the new value from event.view.url and not from the current page state, so that every update gets the same result.
  • If you want full control of view names, set trackViewsManually: true and call startView with a name that has no personal data. The Datadog data security page lists this as an option next to beforeSend.
  • If you do not need the client IP address or geolocation, turn off their collection in the User Data Collection tab of the RUM application. The change applies to new data only.

Do not send an email as the user ID

usr.* is not on the list of properties that beforeSend can change, so the callback cannot clean it. Set usr.id to an opaque ID from your backend, and do not pass an email address or a full name to setUser. You can then still find all sessions of one user, while the user data stays in your own systems.

The same idea works for every field you add: decide what may go out and drop the rest.

Scrub browser logs too

The browser logs SDK adds view.url and view.referrer to every log by default. So a URL with an email address leaks into your logs as well as into RUM, even when the log message itself is clean.

The logs SDK has its own beforeSend(log, context) callback. Datadog lists view.url, view.referrer, message, error.stack and http.url as properties that can hold sensitive data. Return false to discard a log.

import { datadogLogs } from '@datadog/browser-logs';
import { scrub } from './telemetry-scrub';

datadogLogs.init({
  clientToken: '<client-token>',
  site: '<site>',
  service: '<service>',
  env: '<env>',
  version: '<version>',
  beforeSend: (log) => {
    log.view.url = scrub(log.view.url);
    if (log.view.referrer) log.view.referrer = scrub(log.view.referrer);
    log.message = scrub(log.message);
    if (log.error?.stack) log.error.stack = scrub(log.error.stack);
    if (log.http) log.http.url = scrub(log.http.url);
    return true;
  },
});

The browser sends RUM events and browser logs straight to Datadog, or through your proxy if you set one. The Datadog Agent is not in that path, so Agent rules do not clean browser data. Scrub it in the browser.

Set the session replay privacy level

Session replay records the page, so it can show everything that the user sees. The browser SDK has three levels for defaultPrivacyLevel:

Level What the replay shows
mask (default) All text, inputs, images, canvas, links and data-* attributes are masked.
mask-user-input Form fields are masked, while other text is recorded.
allow All text is recorded, except for the fields that are always masked.

Inputs of type password, email and tel, and autocomplete fields such as card data, are always masked. Start with mask, as in our Datadog RUM and APM setup for Next.js, and open up only the elements that you need. To change one element, use data-dd-privacy="allow", "mask", "mask-user-input" or "hidden", or the matching dd-privacy-* class. hidden replaces the element with a block in the replay.

Action names can also contain personal data, for example the text on a button. With defaultPrivacyLevel: 'mask' and enablePrivacyForActionName, the SDK replaces action names that you did not override with Masked Element. Use data-dd-action-name to give important buttons a fixed name.

Replay masking happens in the browser, so the masked text never reaches Datadog. That is a permanent mask. Session Replay access can also be limited with role-based access control.

For a React Native app, the replay SDK uses textAndInputPrivacyLevel:

import {
  SessionReplay,
  TextAndInputPrivacyLevel,
} from '@datadog/mobile-react-native-session-replay';

SessionReplay.enable({
  replaySampleRate: 20,
  textAndInputPrivacyLevel: TextAndInputPrivacyLevel.MASK_SENSITIVE_INPUTS,
});

MASK_ALL is the default and masks all text and inputs. MASK_ALL_INPUTS masks all input fields. MASK_SENSITIVE_INPUTS shows all text and inputs except the ones that the SDK considers sensitive: passwords, emails and phone numbers. So check the screens that show personal data as plain text before you choose it. Images are masked and touches are hidden by default.

Clean server-side telemetry with the Agent

Server requests leak in the same way. In APM, the http.url tag holds the full URL with the query string. By default, the tracer replaces suspicious query values with <redacted>. You can change that regular expression with DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP, or stop collecting the query string with DD_HTTP_SERVER_TAG_QUERY_STRING=false.

The Agent adds a second layer. Query-string obfuscation is off by default, and replace_tags rewrites tag values with a regular expression:

# datadog.yaml
apm_config:
  obfuscation:
    http:
      remove_query_string: true
  replace_tags:
    - name: "*"
      pattern: '[A-Za-z0-9._%+-]+(?:@|%40)[A-Za-z0-9.-]+\.[A-Za-z]{2,}'
      repl: "REDACTED_EMAIL"

In a container, use the environment variables DD_APM_OBFUSCATION_HTTP_REMOVE_QUERY_STRING and DD_APM_REPLACE_TAGS instead.

For logs that the Agent collects from your servers, add a mask_sequences rule. A global rule in datadog.yaml needs Agent 6.10 or later. Rules run in order.

# datadog.yaml
logs_config:
  processing_rules:
    - type: mask_sequences
      name: mask_email
      replace_placeholder: "REDACTED_EMAIL"
      pattern: '[A-Za-z0-9._%+-]+(?:@|%40)[A-Za-z0-9.-]+\.[A-Za-z]{2,}'

The Agent uses Go regular expressions. Test the pattern on a real log line before you roll it out.

Add Sensitive Data Scanner as a safety net

Your own rules can miss a field. Sensitive Data Scanner scans log content, APM span attribute values and RUM event attribute values when Datadog ingests them, before it indexes them. The data leaves your environment first. If that is not acceptable, the Sensitive Data Scanner processor in Observability Pipelines scans the data in your own infrastructure.

Set it up in four steps:

  1. Add a scanning group. A group has a query filter, for example env:prod, and a toggle for each product. Turn on logs, APM and RUM, and enable the group.
  2. Add the library rule Standard Email Address Scanner with its recommended keywords. By default, a keyword must be within 30 characters of the match. Test the rule on a URL-encoded address, and add a custom rule with your own pattern if it does not match.
  3. Choose an action for each rule. Redact, partially redact and hash cannot be undone. Mask can be undone by users with the Data Scanner Unmask permission. A rule without an action only finds matches and changes nothing.
  4. Add the sensitive_data and sensitive_data_category tags, as Datadog recommends. You can then use the tags in searches, dashboards and monitors.

Note these limits:

  • If you sample a product to save scanning volume, you cannot choose an action that obfuscates data for it.
  • The scanner does not scan numbers that are stored as integers or floats.
  • To redact a log tag, remap the tag to an attribute first.

The same masking matters when you send prompts and answers to a language model. Our LLM observability safeguards cover masking of personal data before it goes to a model, a trace or a log.

Verify the fix

A fix is not done until you have seen clean data. Use a test address that you own, never a real customer address.

  1. On staging, open a page with ?email=test%40example.com in the URL. Trigger an error and a browser log that contain the same address.
  2. Search the RUM Explorer for views, resources, errors and actions that contain example.com. Do the same in the Log Explorer and the Trace Explorer.
  3. Open the session replay and check that the form fields and the text with personal data are masked.
  4. Check the matches of the email rule in Sensitive Data Scanner. A match that remains points to a source that you did not clean yet.
  5. Add a monitor on the sensitive_data tag, so that a new leak creates an alert.

The fix applies only to new data. For data that leaked before the fix, you have these options:

  • Logs: Logs Data Deletion deletes indexed logs that match a query in a time frame. An Org Admin must enable it, and you need a role with the Logs Delete Data permission. You can cancel a request for 10 days, and after that the deletion is permanent. It does not delete data derived from the logs, such as generated metrics.
  • Logs: You can also make the logs un-queryable until they age out, or shorten the retention of the index.
  • RUM and other products: Deletion goes through Datadog support. It deletes all data in a time frame and cannot target one application, so compare that with the 30-day retention.

In practice

At an international cosmetics retailer, we reviewed the RUM, log and session replay setup for personal data in October 2026. We checked the RUM beforeSend callback, the code that initialises RUM and the rules in Sensitive Data Scanner, because a scanning rule without an action finds matches but does not redact them.

The follow-up steps were to set an action on the scanning rules, to apply query-string obfuscation and DD_APM_REPLACE_TAGS in the Agent, and to review the changes in a pull request. For the mobile app, our guidance to the developers was to configure the replay sample rate separately from the RUM sample rate and to use MASK_SENSITIVE_INPUTS. Read the full case study.

Checklist

  • List every URL, message and label that can carry personal data.
  • Scrub view.url, view.referrer, resource.url and the error fields in the RUM beforeSend.
  • Scrub view.url, message and http.url in the logs beforeSend.
  • Set an opaque user ID and do not send an email address with setUser.
  • Keep defaultPrivacyLevel: 'mask' and use overrides only where you need them.
  • Turn on query-string obfuscation and replace_tags in the Agent.
  • Add mask_sequences rules for server logs.
  • Give every Sensitive Data Scanner rule an action and the sensitive_data tags.
  • Test with a fake address on staging and add a monitor for new matches.
  • Delete or restrict the data that leaked before the fix.

For a review of what your frontend telemetry collects, see the frontend observability assessment.

Sources

Let's connect

Talk about your project

Tell us about your team and your problem. In 30 minutes we find out whether one of our offers fits, and if none does, we tell you.

Book a 30-minute call