简体   繁体   English

Spring Cloud Sleuth 和 Spring Cloud Stream Kinesis - 如何传播跟踪 ID?

[英]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 ? 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. 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. 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. When I log the message and headers in the microservice that processes this Avro message, I see a different trace ID (and, of course, span ID).当我在处理此 Avro 消息的微服务中记录消息和标头时,我看到了不同的跟踪 ID(当然还有 span ID)。 Propagation does not appear to be configured and/or working properly across this REST controller to Kinesis message context.在此 REST controller 到 Kinesis 消息上下文的传播似乎未配置和/或正常工作。

We are currently using Spring Cloud Hoxton.SR10 , Spring Boot 2.3.9.RELEASE , and Spring Cloud Kinesis 2.0.1.RELEASE .我们目前正在使用 Spring Cloud Hoxton.SR10 、Spring Boot 2.3.9.RELEASE和 Spring Cloud Kinesis 2.0.1.RELEASE

As a side note, I have tried upgrading Spring Cloud Kinesis to 2.0.2.RELEASE , 2.0.3.RELEASE , and 2.0.4.RELEASE but encounter errors with each of these binder upgrades.附带说明一下,我已尝试将 Spring Cloud Kinesis 升级到2.0.2.RELEASE2.0.3.RELEASE2.0.4.RELEASE ,但每次升级都遇到错误。 I'm not certain what version combinations of Spring Cloud, Spring Boot, and Spring Cloud Stream Kinesis work with each other.我不确定 Spring Cloud、Spring Boot 和 Spring Cloud ZEAE835E83C0494A3762ZF Kinesis 与其他 5494A3762229 一起工作的版本组合。

Example code示例代码

@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();
  ...
}

If you use it through the StreamBinder or MessageChannel , it should work, if you use it in the functional way ( Supplier + BlockingQueue ) it should not, the functional way is not supported.如果您通过StreamBinderMessageChannel使用它,它应该可以工作,如果您以功能方式( Supplier + BlockingQueue )使用它,它不应该,不支持功能方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM