HTTP header does not include traceparent

I am trying to use RUM on the spring-boot application https://github.com/spring-projects/spring-petclinic. I would like to link the transactions from the Client side (i.e. JavaScript) to the Server side (i.e. Java).

From the documentation I found that I could do this with distributet tracing. I also looked at this blog entry for instructions on how to do this.

On the Client side I configured the RUM-agent as follows:

    <script src="https://unpkg.com/@elastic/apm-rum@5.9.1/dist/bundles/elastic-apm-rum.umd.min.js"></script>
    <script>
    elasticApm.init({
      serviceName: 'PetClinic',
      serviceVersion: '1.0',

      serverUrl: 'http://localhost:8200', // APM server
      transactionThrottleInterval: 1,

      // distributedTracingOrigins: ['localhost:8080', 'http://localhost:8080', 'http://localhost:8080/'],
      propagateTracestate: true
    })
  </script>

On the Server side I configured the HTTP-Headers and HTTP-Methods as described in this blog entry.

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.logging.Level;
import java.util.logging.Logger;

@Configuration
public class MyCorsConfiguration {
	@Bean
	public FilterRegistrationBean<CorsFilter> corsFilter() {
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		CorsConfiguration config = new CorsConfiguration();
		config.setAllowCredentials(true);
		config.addAllowedOrigin("*");
		config.addAllowedHeader("*");
		config.addAllowedMethod("*");
		source.registerCorsConfiguration("/**", config);
		FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
		bean.setOrder(0);

		Logger.getLogger(MyCorsConfiguration.class.getName()).log(Level.INFO, "Add CORS configuration");

		return bean;
	}
}

The server is started with the Java elastic APM agent to monitor the Server side operations.

-javaagent:path/to/elastic-apm-agent-1.26.0.jar
-Delastic.apm.service_name=PetClinic
-Delastic.apm.application_packages=org.springframework.samples.petclinic.*
-Delastic.apm.server_url=http://localhost:8200
-Delastic.apm.capture_body=all
-Delastic.apm.metrics_interval=0s
-Delastic.apm.trace_methods=org.springframework.samples.petclinic.*

Unfortunately, the HTTP requests that are recorded on the server side to not contain the traceparent or tracestate headers.

{
   "@timestamp":"2021-11-08T14:27:17.838Z",
   "@metadata":{
      "beat":"apm-server",
      "type":"_doc",
      "version":"7.5.1",
      "pipeline":"apm"
   },
   "process":{
      "pid":10372,
      "ppid":16788,
      "title":"C:\\Program Files\\Java\\jdk-11.0.5\\bin\\java.exe"
   },
   "trace":{
      "id":"7ecb81b9873e30c5fad02781df4c791f"
   },
   "observer":{
      "ephemeral_id":"f444e974-855a-4aea-9bfb-8e8feed9f787",
      "type":"apm-server",
      "hostname":"SURT",
      "version":"7.5.1",
      "version_major":7,
      "id":"88e70bb3-faca-4601-9bd3-9c0dd3ef5ebc"
   },
   "agent":{
      "version":"1.26.0",
      "ephemeral_id":"7b297f69-94e2-4ca5-84c6-8ffa5495c239",
      "name":"java"
   },
   "host":{
      "architecture":"amd64",
      "os":{
         "platform":"Windows 10"
      },
      "ip":"127.0.0.1",
      "hostname":"SURT",
      "name":"SURT"
   },
   "source":{
      "ip":"::1"
   },
   "timestamp":{
      "us":1636381637838004
   },
   "http":{
      "version":"1.1",
      "request":{
         "method":"get",
         "cookies":{
            "Idea-66c2ac0f":"3b034733-f14d-4063-9336-f9de764af39d"
         },
         "headers":{
            "Upgrade-Insecure-Requests":[
               "1"
            ],
            "Sec-Ch-Ua-Platform":[
               "\"Windows\""
            ],
            "Sec-Ch-Ua-Mobile":[
               "?0"
            ],
            "Accept":[
               "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
            ],
            "Sec-Fetch-Dest":[
               "document"
            ],
            "Accept-Language":[
               "en-US,en;q=0.9"
            ],
            "Connection":[
               "keep-alive"
            ],
            "Referer":[
               "http://localhost:8080/owners/find"
            ],
            "Sec-Fetch-User":[
               "?1"
            ],
            "Host":[
               "localhost:8080"
            ],
            "User-Agent":[
               "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
            ],
            "Accept-Encoding":[
               "gzip, deflate, br"
            ],
            "Sec-Ch-Ua":[
               "\"Google Chrome\";v=\"95\", \"Chromium\";v=\"95\", \";Not A Brand\";v=\"99\""
            ],
            "Sec-Fetch-Site":[
               "same-origin"
            ],
            "Sec-Fetch-Mode":[
               "navigate"
            ]
         },
         "socket":{
            "remote_address":"0:0:0:0:0:0:0:1",
            "encrypted":false
         }
      },
      "response":{
         "status_code":200,
         "headers":{
            "Date":[
               "Mon, 08 Nov 2021 14:27:18 GMT"
            ],
            "Keep-Alive":[
               "timeout=60"
            ],
            "Connection":[
               "keep-alive"
            ],
            "Vary":[
               "Origin",
               "Access-Control-Request-Method",
               "Access-Control-Request-Headers",
               "Origin",
               "Access-Control-Request-Method",
               "Access-Control-Request-Headers",
               "Origin",
               "Access-Control-Request-Method",
               "Access-Control-Request-Headers"
            ],
            "Content-Type":[
               "text/html;charset=UTF-8"
            ],
            "Content-Language":[
               "en-US"
            ],
            "Transfer-Encoding":[
               "chunked"
            ]
         },
         "headers_sent":true,
         "finished":true
      }
   },
   "url":{
      "port":8080,
      "scheme":"http",
      "full":"http://localhost:8080/vets.html",
      "domain":"localhost",
      "path":"/vets.html"
   },
   "processor":{
      "name":"transaction",
      "event":"transaction"
   },
   "transaction":{
      "name":"VetController#showVetList",
      "duration":{
         "us":411618
      },
      "type":"request",
      "result":"HTTP 2xx",
      "sampled":true,
      "span_count":{
         "dropped":0,
         "started":54
      },
      "id":"b9ee709d100bb46b"
   },
   "ecs":{
      "version":"1.1.0"
   },
   "service":{
      "name":"PetClinic",
      "node":{
         "name":"SURT"
      },
      "language":{
         "version":"11.0.5",
         "name":"Java"
      },
      "runtime":{
         "version":"11.0.5",
         "name":"Java"
      },
      "framework":{
         "name":"Spring Web MVC",
         "version":"5.3.6"
      }
   },
   "user_agent":{
      "original":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
   },
   "client":{
      "ip":"::1"
   }
}

If I understood the documentation correctly traceparent and tracestate should be added to the HTTP-Headers of the requests. Am I correct in that understanding or did I get something wrong here?

Does anyone know what is wrong or missing in my configuration?

APM Agent language and version:

JavaScript; v 5.9.1
Java; v 1.26.0

Browser version:

I tried it with Firefox 93.0 (64-Bit)
and Chrome Version 95.0.4638.69 (Official Build) (64-bit)

Thanks for reading!

Your CORS handling may not be set properly.
You can open your browser debugging tools (e.g. Chrome Developer Tools) and debug such a request. Each request should be preflighted with an OPTIONS HTTP request containing some CORS-related headers, and the response should contain all headers added through MyCorsConfiguration.
If there is no such OPTIONS request at all before the GET, it may be because you omitted the distributedTracingOrigins setting. Try to uncomment it as is and it should fix that.

If this doesn't help, please add here all details from both OPTIONS and GET requests as you see them in the browser dev tools.

I hope this helps.

Hi,

Thanks for helping!

Unfortunatly, I do not see a OPTIONS HTTP request, even after removing the comment from distributedTracingOrigins.

The elastic RUM agent should be able to work also for the type document requests right? Or does it only work for XHR or other fetch requests?

Hi @sfischer ,

Distributed tracing headers are added only for API calls (XHR and Fetch) by the RUM agent. If you want to trace the HTML document generation, you would have to set up the RUM agent with appropriate page-load trace details.

Please let us know if you need any help.

Thanks,
Vignesh

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