Last active
August 24, 2019 02:08
-
-
Save zhaohuabing/ab0a0109e597ef6351edc1a87ad9d8f5 to your computer and use it in GitHub Desktop.
Enhance Istio Distributed Tracing with OpenTracing-eshop-checkout
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
@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