# Enable Distributed Tracing for Dynatrace RUM Applications

**URL:** <https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140>\
**Category:** Real User Monitoring\
**Tags:** real-user-monitoring-classic\
**Created:** [April 15, 2024, 2:03pm UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140 "2024-04-15T14:03:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KamilA](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@KamilA](https://community.dynatrace.com/u/KamilA)\
**Post date:** [April 15, 2024, 2:03pm UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140/1 "2024-04-15T14:03:49Z")

</div>

_Summary:&nbsp;This post explains why distributed tracing may not appear for a RUM application. It covers requirements such as backend service detection, propagation headers, and where data will or will not show up in Dynatrace._

Our problem:

HTTP errors handled by the Dynatrace web application don’t have an assigned service, so we are not able to see distributed tracing

State of the matter is:

- We have defined a web application in Dynatrace using the agentless RUM option (Injection format: **JavaScript tag** )
- The frontend application is developed in Angular v17
- Frontend communicates with backend via Apigee proxy and Istio, it looks like: HTPP request from Frontend app → apigee proxy → Istio → backend service
- Our one Dynatrace web application monitors 2 environments (test, prod), app URLs look like: [https://app.test.group.example.com](https://app.test.group.example.com) [https://app.group.example.com](https://app.group.example.com)
- The frontend app is hosted on Amazon CloudFront
- Our frontend app calls the backend via Apigee proxy, api urls look like [https://api-test.example.com](https://api-test.example.com) [https://api.example.com](https://api.example.com)
- For backend, we have a separate service in Dynatrace for the test and prod environments
- Cookies are included in XHR calls (we checked and backend service receives Dynatrace cookies send from frontend)
- We checked and **x-dtc** header isn’t set when we have **(https:\/\/)?[a-z|-]\*\.example\.com\/?\S\*** regex in “ **Link cross-origin XHR actions and their distributed trace** s” option
- In frontend Dynatrace web application we have defined request error rules and **HTTP 400-499** and **500-599** errors are captured, they impact Apdex and are considered for Davis
- Our Angular interceptor responsible for capturing HTTP errors using **Dynatrace JavaScript API:**

```javascript
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
    if (!window.dtrum) {
        return next.handle(req);
    }

    const xhrActionId: number = window.dtrum?.enterXhrAction(`HTTP ${req.method} request`, 1, req.url);

    return next.handle(req).pipe(
        tap({
            next: (): void => {},
            error: (error: HttpErrorResponse): void => {
                window.dtrum?.markXHRFailed(error.status, error.message, xhrActionId);
            }
        }),
        finalize((): void => {
            window?.dtrum?.leaveXhrAction(xhrActionId);
        })
    );

```

- In Dynatrace web application settings we have:
  - In **Capturing → Async web requests and SPAs** section: **Angular** &nbsp;toggle is off and **Capture XmlHttpRequest (XHR), Use Proxy API for XHRs, Capture fetch() requests** toggles are on
  - In **Capturing → Custom configuration properties** section we have **cce=1** custom configuration property added
  - Page group detection is default
  - In **Capturing → Content capture** section all toggles are on

- Our backend services are monitored by OneAgent, developed using Spring boot 3.2.2 and Java 21, deployed on AWS using Kubernetes

What did we miss that distributed tracing doesn’t work for our RUM application?

---

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [April 19, 2024, 1:47pm UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140/2 "2024-04-19T13:47:48Z")

</div>

Hi&nbsp;[@KamilA](https://community.dynatrace.com/user/70734)&nbsp;  
In certain cases, if you use agentless and if you activate cross-origin, it may be necessary to pass the x-dtc header into CORS in order to be able to link user actions (or errors) to backend traces.

documentation link :&nbsp;[https://docs.dynatrace.com/docs/platform-modules/digital-experience/web-applications/initial-setup/l…](https://docs.dynatrace.com/docs/platform-modules/digital-experience/web-applications/initial-setup/link-cross-origin-xhrs)

---

<div class="post-metadata">

**Author:** ![KamilA](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@KamilA](https://community.dynatrace.com/u/KamilA)\
**Post date:** [April 23, 2024, 7:19am UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140/3 "2024-04-23T07:19:13Z")

</div>

I’ve configured&nbsp; **Access-Control-Allow-Headers: x-dtc** header but still **x-dtc** header isn’t set. Should it be added automatically by JavaScript API? Am I right?

---

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [April 23, 2024, 7:42am UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140/4 "2024-04-23T07:42:29Z")

</div>

Oui, mais il faut veiller à l’autoriser dans le CORS (peut-être sur API Gateway par exemple).

---

<div class="post-metadata">

**Author:** ![KamilA](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@KamilA](https://community.dynatrace.com/u/KamilA)\
**Post date:** [April 25, 2024, 12:46pm UTC](https://community.dynatrace.com/t/enable-distributed-tracing-for-dynatrace-rum-applications/45140/5 "2024-04-25T12:46:27Z")

</div>

But the **CORS** error will show up only when **x-dtc** header is added so in my opinion regex in&nbsp; **Link cross-origin XHR actions and their distributed traces** &nbsp;doesn’t work because&nbsp; **x-dtc** header isn’t added
