![](/img/trans.png)
[英]Spring Cloud Sleuth trace ID propagation via Spring Cloud Stream Binder for AWS Kinesis
[英]Spring Cloud Sleuth and Spring Cloud Stream Kinesis - How to propagate trace IDs?
Do Spring Cloud Sleuth tracing headers get injected into Spring Cloud Stream Kinesis messages like they do for RabbitMq and Kafka as described here ? We have a REST controller that, after processing a POST request but right before sending the response to the client, sends an Avro message to Kinesis that summarizes the transaction using Spring Cloud Stream Kinesis. I want to ensure that the trace id started in the REST controller is propagated to the Spring Cloud Stream Kinesis message, and I am unsure of how to configure this or whether it's even supported by the framework. 當我在處理此 Avro 消息的微服務中記錄消息和標頭時,我看到了不同的跟蹤 ID(當然還有 span ID)。 在此 REST controller 到 Kinesis 消息上下文的傳播似乎未配置和/或正常工作。
我們目前正在使用 Spring Cloud Hoxton.SR10
、Spring Boot 2.3.9.RELEASE
和 Spring Cloud Kinesis 2.0.1.RELEASE
。
附帶說明一下,我已嘗試將 Spring Cloud Kinesis 升級到2.0.2.RELEASE
、 2.0.3.RELEASE
和2.0.4.RELEASE
,但每次升級都遇到錯誤。 我不確定 Spring Cloud、Spring Boot 和 Spring Cloud ZEAE835E83C0494A3762ZF Kinesis 與其他 5494A3762229 一起工作的版本組合。
示例代碼
@PostMapping(
value = "/accountEntry",
consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<Confirmation> createAccountEntry(
@RequestBody final AccountEntry accountEntry,
final HttpServletRequest request) {
final AccountEntryEvent accountEntryEvent =
new AccountEntryEvent(convertToAvro(accountEntry), AccountEntryEventType.CREATE_ACCOUNT_ENTRY);
accountEntryChannels
.accountEntryRequest()
.send(
MessageBuilder.withPayload(accountEntryEvent)
.build());
final Confirmation confirmation = buildConfirmation();
final EntityModel<Confirmation> confirmationEntityModel =
new EntityModel<>(confirmation);
return new ResponseEntity<>(confirmationEntityModel, HttpStatus.ACCEPTED);
}
// with a brave.Tracer instance autowired, I'm able to obtain the trace id as follows
protected String getTraceId() {
return tracer.currentSpan().context().traceIdString();
}
@Component
public interface AccountEntryChannels {
@Output("account-entry-request")
SubscribableChannel accountEntryRequest();
...
}
如果您通過StreamBinder
或MessageChannel
使用它,它應該可以工作,如果您以功能方式( Supplier
+ BlockingQueue
)使用它,它不應該,不支持功能方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.