# RUM & APM Traces are not having same trace id

**URL:** <https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029>\
**Category:** APM\
**Tags:** rum\
**Created:** [March 6, 2023, 5:34am UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029 "2023-03-06T05:34:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratikshatiwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratikshatiwari/32/116646_2.png) [@pratikshatiwari](https://discuss.elastic.co/u/pratikshatiwari)\
**Post date:** [March 6, 2023, 5:34am UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/1 "2023-03-06T05:34:23Z")

</div>

hello team,

I came across the issue whee i am not getting same trace id for RUM & APM transaction.

E.g. i initiate the transaction "add product to basket" and i get the transaction detail in APM (service - clothing) & RUM (service - clothing-rum) both but the transaction contains different trace id

kindly suggest what we can do to get the same trace id?

My infrastructure details as below:

Application Hosted on : [ASP.Net](http://ASP.Net) Core (dotnet6)

APM agent setup in program.cs file

################ program.cs ####################  
using Elastic.Apm.NetCoreAll;

var configuration = GetConfiguration();  
app.UseAllElasticApm(configuration);

############### appsettings.json ####################

"ElasticApm": {  
"ServerUrls": "[https://XX.XX.XX.XX:8200](https://XX.XX.XX.XX:8200)",  
"ServerCert": "~/lib/cert/ca.crt",  
"VerifyServerCert": "false",  
"SecretToken": "",  
"ServiceName": "clothing",  
"Environment": "DEV"  
}

####################################################################################

############### RUM ########################

```
<script src="~/lib/apm-rum/elastic-apm-rum.umd.min.js" crossorigin></script>
<script>
    elasticApm.init({
        serviceName: 'clothing-rum',
        serverUrl: 'https://XX.XX.XX.XX:8200',
        SERVER_CERT: "~/lib/cert/ca.crt",
        VerifyServerCert: "true",
        environment: 'DEV'
    });
</script>

```

####################################################################################

Regards  
Pratiksha

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [March 6, 2023, 11:42am UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/2 "2023-03-06T11:42:48Z")

</div>

Hi @pratikshatiwari,

It looks to me that you are making cross-origin requests. While the RUM agent does support distributed tracing out of the box, it only supports requests on the same origin unless you specify the cross-origin url via the [`distributedTracingOrigins `](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html#enable-cors) configuration. Check out the [distributed tracing guide in the docs](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html).

Can you check if enabling cross-origin requests fixes your issue?

---

<div class="post-metadata">

**Author:** ![pratikshatiwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratikshatiwari/32/116646_2.png) [@pratikshatiwari](https://discuss.elastic.co/u/pratikshatiwari)\
**Post date:** [March 6, 2023, 2:04pm UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/3 "2023-03-06T14:04:39Z")

</div>

Hi carly,

Thank you for your responce

i have tried setting up RUM agent with below configuration in order to enable distributedtracing from rum agent but still i dont get any improvment

RUM agent configuration as below:

##########

```auto
    <script src="~/lib/apm-rum/elastic-apm-rum.umd.min.js" crossorigin></script>
    <script>
        elasticApm.init({
            serviceName: 'clothing-rum',
            serverUrl: 'https://XX.XX.XX.XX:8200',
            SERVER_CERT: "~/lib/cert/ca.crt",
            VerifyServerCert: "false",
            environment: 'DEV',
            distributedTracingOrigins: ['https://localhost:44315', 'https://localhost:5099/*', '*']
        });
    </script>

```

##########

Also APM Server file configuration as below:

```auto
#### APM Server Configuration ##########

apm-server:
  host: "127.0.0.1"
  ssl.enabled : true
  ssl.certificate: "/etc/apm-server/node1.crt"
  ssl.key: "/etc/apm-server/node1.key"
  ssl.certificates_authorities: "/opt/apm-server/ca.crt"
  ssl.verification_mode: certificate

  rum:
    enabled: true
    exclude_from_grouping: "^/webpack"

    source_mapping:
      enabled: true
      elasticsearch:
        hosts: ["http://127.0.0.1:9201"]
        ssl.certificate_authorities:
        username: "elastic"
        password: "elastic"
      cache:
        expiration: 5m
      index_pattern: "apm-*-sourcemap*"

  kibana:
    enabled: true
    host: "XX.XX.XX.XX:5601"
    protocol: "http"
    username: "elastic"
    password: "elastic"

#-------------------------- Elasticsearch output --------------------------
output.elasticsearch:
  hosts: ["http://127.0.0.1:9201"]
  username: "elastic"
  password: "elastic"

  xpack.monitoring.enabled: true

logging:
  files:
    keepfiles: 7
    name: apm-server
    path: /etc/apm-server
    permissions: 384
    rotateeverybytes: 10485760
  metrics:
    enabled: true
  to_files: true

Access-Control-Allow-Headers: traceparent, tracestate
Access-Control-Allow-Methods: [allowed-methods]
Access-Control-Allow-Origin: [request-origin]

```

##########

---

<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 7, 2023, 10:35pm UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/4 "2023-03-07T22:35:59Z")

</div>

Hi @pratikshatiwari,

this part of our doc could be useful in your case: [Public API | APM .NET Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#api-transaction-ensure-parent-id)

---

<div class="post-metadata">

**Author:** ![pratikshatiwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pratikshatiwari/32/116646_2.png) [@pratikshatiwari](https://discuss.elastic.co/u/pratikshatiwari)\
**Post date:** [March 10, 2023, 3:31pm UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/5 "2023-03-10T15:31:53Z")

</div>

Hi @GregKalapos

Thank for reply yes this did helped me to get the traces of teh API from same ASP dotnet project, but not from the other project which i s a part of same microservice,

i hvae microservice project with below projects

Web - frontend - [https://localhost:1234](https://localhost:1234)  
Public API - Admin API - [https://localhost:5678](https://localhost:5678)

RUM configurations exist in Web project which have project html file but using this configuration i can't get the Public API traces running on [https://localhost:5678](https://localhost:5678)

i have the following configuration in web cshtml file

```
<script src="~/lib/apm-rum/elastic-apm-rum.umd.min.js" crossorigin="anonymous"></script>
<script>
    elasticApm.init({
        serviceName: 'clothing-rum',
        serverUrl: 'https://xx.xx.xx.xx:8200',
        "ServerCert": "~/lib/cert/ca.crt",
        "VerifyServerCert": "true",
        "Environment": "ecommerce",
        distributedTracingOrigins: ['https://localhost:1234'],
        //var transaction = agent.Tracer.StartTransaction("Transaction1", "sample");
        //transaction.SetService("clothing", "1.0-beta1");
        pageLoadTraceId: '@Elastic.Apm.Agent.Tracer.CurrentTransaction?.TraceId',
        pageLoadSpanId: '@Elastic.Apm.Agent.Tracer.CurrentTransaction?.EnsureParentId()',
        pageLoadSampled: @Json.Serialize(Elastic.Apm.Agent.Tracer?.CurrentTransaction.IsSampled),
    });
</script>

```

Regards  
Pratiksha

---

<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, 2023, 3:32pm UTC](https://discuss.elastic.co/t/rum-apm-traces-are-not-having-same-trace-id/327029/6 "2023-04-07T15:32:17Z")

</div>

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