Proxy Your Browser RUM Data

Overview

The RUM Browser SDK can be configured to send requests through a proxy. Requests made still need to be forwarded to Datadog.

SDK initialization

When you set the proxyUrl initialization parameter, all RUM data is sent to the specified URL using the POST method (for example, https://www.proxy.com/foo).

import { Datacenter, datadogRum } from '@datadog/browser-rum';

datadogRum.init({
    applicationId: '<DATADOG_APPLICATION_ID>',
    clientToken: '<DATADOG_CLIENT_TOKEN>',
    site: '<DATADOG_SITE>',
    proxyUrl: '<YOUR_PROXY_URL>',
});
<script>
 (function(h,o,u,n,d) {
   h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
   d=o.createElement(u);d.async=1;d.src=n
   n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-rum-v4.js','DD_RUM')
  DD_RUM.onReady(function() {
    DD_RUM.init({
        clientToken: '<CLIENT_TOKEN>',
        applicationId: '<APPLICATION_ID>',
        proxyUrl: '<YOUR_PROXY_URL>',
    })
  })
</script>
window.DD_RUM &&
    window.DD_RUM.init({
        clientToken: '<CLIENT_TOKEN>',
        applicationId: '<APPLICATION_ID>',
        proxyUrl: '<YOUR_PROXY_URL>',
    });

Proxy setup

When your proxy receives data from the RUM Browser SDK, it must be forwarded to Datadog. The RUM Browser SDK adds the ddforward query parameter to all POST requests to your proxy. This query parameter contains the URL where all data must be forwarded to.

To successfully proxy request to Datadog:

  1. Add a X-Forwarded-For header containing the request client IP address for accurate geoIP.
  2. Forward the request to the URL set in the ddforward query parameter using the POST method.
  3. The request body must remain unchanged.

Ensure the ddforward attribute points to a valid Datadog endpoint for your Datadog site. Failure to do so may result in an insecure configuration.

The site parameter is an SDK initialization parameter. Valid intake URL patterns for each site are listed below:

SiteValid intake URL PatternSite Parameter
US1https://*.browser-intake-datadoghq.com/*datadoghq.com
US3https://*.browser-intake-us3-datadoghq.com/*us3.datadoghq.com
US5https://*.browser-intake-us5-datadoghq.com/*us5.datadoghq.com
EU1https://*.browser-intake-datadoghq.eu/*datadoghq.eu
US1-FEDhttps://*.browser-intake-ddog-gov.com/*ddog-gov.com
SiteValid intake URL PatternSite Parameter
US1https://*.logs.datadoghq.com/*datadoghq.com
US3https://*.logs.us3-datadoghq.com/*us3.datadoghq.com
EU1https://*.logs.datadoghq.eu/*datadoghq.eu
US1-FEDhttps://*.logs.ddog-gov.com/*ddog-gov.com

Further Reading

Additional helpful documentation, links, and articles: