# Custom transactions cannot match the trace.id of the backend

**URL:** <https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278>\
**Category:** APM\
**Tags:** rum\
**Created:** [March 12, 2020, 8:18am UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278 "2020-03-12T08:18:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [March 12, 2020, 8:18am UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/1 "2020-03-12T08:18:26Z")

</div>

![761af108-aced-462d-8f3f-56265a4bdc37](https://us1.discourse-cdn.com/elastic/original/3X/4/b/4b61238737f943d779965696a9582f08dde5d76a.png)

![99915837397128763](https://us1.discourse-cdn.com/elastic/original/3X/5/8/58aea97af25c6c905bf059035575ac643d30b862.png)  
The frontend generates a trace.id and the backend adds a trace.id

What can I do to match trace.id

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [March 14, 2020, 8:30pm UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/2 "2020-03-14T20:30:04Z")

</div>

Hi @wajika,

I assume this is the same as [Custom transactions cannot match the trace.id of the backend](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278).

Is the `elastic-apm-traceparent` header added to the HTTP request? Can you verify that?

If you paste here the logs from the .NET Agent, I can also verify if the .NET Agent receives the necessary header or not. I see you already set the .NET Agent debug to `Debug` level, I'd need logs from at least `Debug`, so make sure that's still set if you send logs.

Also, just to make sure I understand you correctly.

> What can I do to match trace.id

You mean that the trace.id of the transaction on the backend (.NET) and the trace.id of the transaction on the frontend (JS) don't match - that is the issue, right? So in Kibana you don't see those 2 transactions as a single trace - that is the issue here, right?

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [March 16, 2020, 3:47am UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/3 "2020-03-16T03:47:13Z")

</div>

You mean that the trace.id of the transaction on the backend (.NET) and the trace.id of the transaction on the frontend (JS) don't match ------- yes  
So in Kibana you don't see those 2 transactions as a single trace ----- yes

Can see elastic-apm-traceparent on the browser without using Custom Transactions.

 ![tracertparent header](https://us1.discourse-cdn.com/elastic/original/3X/6/9/6988be70bd11bb3308297c5a5ca937bd03fd4a2d.png)

I looked at the document, but I couldn't find the reason.  
[https://www.elastic.co/guide/en/apm/agent/rum-js/current/custom-transactions.html](https://www.elastic.co/guide/en/apm/agent/rum-js/current/custom-transactions.html)

 ![22](https://us1.discourse-cdn.com/elastic/original/3X/5/0/50a323c01ff3f4ca51e470c9bc72d258e68b3f4d.png)

I didn't see any useful information in the backend(.net) log.  
[https://pastebin.com/rJVXxi6d](https://pastebin.com/rJVXxi6d)

 ![init](https://us1.discourse-cdn.com/elastic/original/3X/8/3/838a5717929958d8b4be90eed7d14bdf7c1507a9.png)

---

<div class="post-metadata">

**Author:** ![vigneshshanmugam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vigneshshanmugam/32/40324_2.png) [@vigneshshanmugam](https://discuss.elastic.co/u/vigneshshanmugam)\
**Post date:** [March 17, 2020, 2:17pm UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/4 "2020-03-17T14:17:59Z")

</div>

Hi @wajika,

Distributed tracing works out of the box only for Managed transactions (Auto instrumented Transactions/Spans created by the agent) as the agent has to patch the outgoing call and add necessary headers (`elastic-apm-traceparent`).

For custom XHR span (`httpSpan` from your example), you would need to set the `elastic-apm-traceparent` header on the underlying HTTP request (XHR or Fetch). You can do something like this for XHR

```auto
var httpspan = transaction.startSpan('POST', 'external')
// get header value from span
// https://github.com/elastic/apm-agent-rum-js/blob/efece2590c3287aff4aefac031a79918bd76160f/packages/rum-core/src/common/utils.js#L66-L80

var headerValue = getHeaderValue(httpSpan)
// add the header to the XHR call
xhr.setRequestHeader('elastic-apm-traceparent', headerValue)

```

This is bit painful and hacky, We already have an [issue](https://github.com/elastic/apm-agent-rum-js/issues/468) to expose an API from the RUM agent to make it easier to do this for custom instrumentations.

Thanks,  
Vignesh

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [March 18, 2020, 1:45am UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/5 "2020-03-18T01:45:19Z")

</div>

Problem solved, thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 7, 2020, 9:45pm UTC](https://discuss.elastic.co/t/custom-transactions-cannot-match-the-trace-id-of-the-backend/223278/6 "2020-04-07T21:45:19Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
