# HTTP header does not include traceparent

**URL:** <https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649>\
**Category:** APM\
**Tags:** java, rum\
**Created:** [November 8, 2021, 3:21pm UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649 "2021-11-08T15:21:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfischer](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@sfischer](https://discuss.elastic.co/u/sfischer)\
**Post date:** [November 8, 2021, 3:21pm UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649/1 "2021-11-08T15:21:45Z")

</div>

I am trying to use RUM on the spring-boot application [https://github.com/spring-projects/spring-petclinic](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](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html). I also looked at [this blog entry](https://www.elastic.co/de/blog/performing-real-user-monitoring-rum-with-elastic-apm) for instructions on how to do this.

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

```auto
    <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](https://www.elastic.co/de/blog/performing-real-user-monitoring-rum-with-elastic-apm).

```java
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.

```auto
-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.

```auto
{
   "@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!

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 8, 2021, 4:17pm UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649/2 "2021-11-08T16:17:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sfischer](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@sfischer](https://discuss.elastic.co/u/sfischer)\
**Post date:** [November 9, 2021, 7:56am UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649/3 "2021-11-09T07:56:13Z")

</div>

Hi,

Thanks for helping!

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

 ![chrome-requests](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e61a57c662b9c80d374920db33ad8641851a6bc5.png)

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?

---

<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:** [November 9, 2021, 3:29pm UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649/4 "2021-11-09T15:29:27Z")

</div>

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.

> **[Distributed Tracing | APM Real User Monitoring JavaScript Agent Reference...](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html#dynamic-html-doc)**

Please let us know if you need any help.

Thanks,  
Vignesh

---

<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:** [November 30, 2021, 11:29am UTC](https://discuss.elastic.co/t/http-header-does-not-include-traceparent/288649/5 "2021-11-30T11:29:50Z")

</div>

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