Skip to content

Instantly share code, notes, and snippets.

@pavolloffay
Last active February 2, 2018 13:05
Show Gist options
  • Save pavolloffay/164e20c4f43abb24cbb6d1c35d4834d5 to your computer and use it in GitHub Desktop.
Save pavolloffay/164e20c4f43abb24cbb6d1c35d4834d5 to your computer and use it in GitHub Desktop.
opentracing-istio-envoy
@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