Skip to content

Instantly share code, notes, and snippets.

@zhaohuabing
Last active August 24, 2019 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaohuabing/ab0a0109e597ef6351edc1a87ad9d8f5 to your computer and use it in GitHub Desktop.
Save zhaohuabing/ab0a0109e597ef6351edc1a87ad9d8f5 to your computer and use it in GitHub Desktop.
Enhance Istio Distributed Tracing with OpenTracing-eshop-checkout
@RequestMapping(value = "/checkout")
public String checkout(@RequestHeader HttpHeaders headers) {
  String result = "";
  // Use HTTP GET in this demo. In a real world use case,We should use HTTP POST
  // instead.
  // The three services are bundled in one jar for simplicity. To make it work,
  // define three services in Kubernets.
  result += restTemplate.exchange("http://inventory:8080/createOrder", HttpMethod.GET,
  new HttpEntity<>(passTracingHeader(headers)), String.class).getBody();
  result += "<BR>";
  result += restTemplate.exchange("http://billing:8080/payment", HttpMethod.GET,
  new HttpEntity<>(passTracingHeader(headers)), String.class).getBody();
  result += "<BR>";
  result += restTemplate.exchange("http://delivery:8080/arrangeDelivery", HttpMethod.GET,
  new HttpEntity<>(passTracingHeader(headers)), String.class).getBody();
  return result;
}
private HttpHeaders passTracingHeader(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");
  return tracingHeaders;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment