我有一个服务可以对另一个服务进行 GET API 调用。我目前正在使用开放遥测技术在当前服务中进行跟踪。我想将跟踪信息传递给 GET API 调用,据我所知,传出 REST API 调用中的跟踪信息是通过标头“traceparent”和“tracestate”传递的。我可以在 API 调用之前手动添加这些标头,这是传递跟踪信息的好方法吗?
以下是我对 REST API 的基本 GET API 调用。
public List<String> getBooks(String bookId){
Span getBookSpan = this.traceService.getTracer()
.spanBuilder(url)
.setAttribute("method","GET")
.startSpan();
UriComponentBuilder builder = UriComponentBuilder.fromUriString(url);
HttpHeader headers = new HttpHeaders();
headers.add("Authorization", getToken());
headers.add("traceparent", getTraceId());
ResponseEntity<String> responseEntity = restTemplate.exchange(builder.toUrlString(),
HttpMethod.GET, new HttpEntity<>(headers), String.class);
}