---
layout: post
title:  "Tracking User Sessions in Datadog"
date:   2021-06-22 10:43:34 -0500
categories: datadog user
---
Adding to our ever-increasing suite of Datadog tools at the Orchard is: RUM (Real User Monitoring). According to their [docs](https://docs.datadoghq.com/real_user_monitoring/), "Datadog’s Real User Monitoring (RUM) gives you end-to-end visibility into the real-time activity and experience of individual users." This means the ability to see user sessions (each click and page load, along with analytics), and connect those frontend actions to APM traces. Now we have a true frontend-to-backend connected look at users' experiences in Workstation, Insights, and Settings - with more apps to come! If you've ever used Mouseflow, you'll find that RUM gives you a lot of the same capabilities, with a more seamless UI and the ability to connect directly to backend traces. 

**Datadog RUM Demo**

<!-- blank line -->
<figure class="video_container">
  <iframe src="https://drive.google.com/file/d/1r161YgsJcUOHfNkizmpmCLI_8Y9HJfl0/preview" frameborder="10" allowfullscreen="true"> </iframe>
</figure>
<!-- blank line -->


**Setting Up RUM in Your Frontend Application**

If your application already has Datadog hooked up (which it likely does), most of the work is in adding a `datadogRUM.init()` call to your Datadog client initialization. Make sure you have the optional `allowedTracingOrigins` parameter, with a list of request origins that will be used to inject tracing headers. 
For example:

```
datadogRum.init({
                service: 'Insights',
                applicationId,
                clientToken,
                datacenter: 'us',
                env,
                version,
                sampleRate: 100,
                trackInteractions: true,
                allowedTracingOrigins: ['https://qa-ows-grass.theorchard.io', 'https://ows-grass.theorchard.io']
            });
```
Here is an [example PR](https://github.com/theorchard/frontend-insights/pull/1050/files) from Frontend Insights. 

You'll know you've succeeded when you see these `x-datadog` headers in your network calls!

![RUM Headers](/assets/datadog_RUM_trace_id.png)
