Last active
February 2, 2018 13:05
-
-
Save pavolloffay/164e20c4f43abb24cbb6d1c35d4834d5 to your computer and use it in GitHub Desktop.
opentracing-istio-envoy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
public class HelloController { | |
@Autowired | |
private RestTemplate restTemplate; | |
@RequestMapping(value = "/hello") | |
public String hello() { | |
return "Hello from Spring Boot!"; | |
} | |
@RequestMapping("/chaining") | |
public String chaining(@RequestHeader HttpHeaders headers) { | |
HttpHeaders tracingHeaders = new HttpHeaders(); | |
extractHeader(headers, tracingHeaders, "x-request-id"); | |
extractHeader(headers, tracingHeaders, "x-b3-traceid"); | |
extractHeader(headers, tracingHeaders, "x-b3-spanid"); | |
extractHeader(headers, tracingHeaders, "x-b3-parentspanid"); | |
extractHeader(headers, tracingHeaders, "x-b3-sampled"); | |
extractHeader(headers, tracingHeaders, "x-b3-flags"); | |
extractHeader(headers, tracingHeaders, "x-ot-span-context"); | |
ResponseEntity<String> response = restTemplate | |
.exchange("http://spring-boot:8080/hello", HttpMethod.GET, new HttpEntity<>(tracingHeaders), String.class); | |
return "Chaining + " + response.getBody(); | |
} | |
private static void extractHeader(HttpHeaders headers, HttpHeaders extracted, String key) { | |
List<String> vals = headers.get(key); | |
if (vals != null && !vals.isEmpty()) { | |
extracted.put(key, Arrays.asList(vals.get(0))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment