RUM & APM Traces are not having same trace id

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 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",
"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

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 configuration. Check out the distributed tracing guide in the docs.

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

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:

##########

    <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:

#### 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]

##########

Hi @pratikshatiwari,

this part of our doc could be useful in your case: Public API | APM .NET Agent Reference [1.x] | Elastic

1 Like

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
Public API - Admin API - 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

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

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