spring - PCF 上的 128 位侦探跟踪 ID

标签 spring cloud-foundry spring-cloud-sleuth

我正在尝试使用 Sleuth 生成的 128 位 TraceId 作为发送到我的 Controller 的请求的唯一标识符。我知道默认的 traceId 是 64,要更改它,我必须将以下内容添加到 application.properties:

spring.sleuth.trace-id128=true

这适用于我的本地,但是当我将它部署到 PCF 时,跟踪 ID 是 64 位。我创建了一个示例项目,其中只有一个简单的 Controller 来演示这一点。

@RestController
public class Controller {
    private Logger logger = LoggerFactory.getLogger(Controller.class);
    @Autowired
    private Tracer tracer;
    @GetMapping("/")
    public void test(){
        logger.info("LOGGED +["+tracer.currentSpan().context().traceIdString()+"]");
    }
}

在我的本地,它会打印:

com.example.demo.Controller: LOGGED + [5bfcb33c9d564481479f2c212ec08143]

在 PCF 中,它打印:

om.example.demo.Controller : LOGGED + [97a1168857dc7088]

PCF 是否会覆盖此配置?

更新

在我的请求中包含“X-B3-TraceId”和“X-B3-SpanId”,traceId 现在是 128 位但与请求 header 中传递的字符串不同。

Details from log

最佳答案

PCF,更具体地说是 Gorouter,可能正在创建跟踪 ID 并将其传播到您的应用程序,而不是创建新的 128 位跟踪 ID,而是重用现有的 64 位跟踪 ID。

PCF 支持 Zipkin Tracing,这是默认启用的,因此在大多数环境中都是启用的。

https://docs.pivotal.io/pivotalcf/2-3/adminguide/zipkin_tracing.html

根据文档,Gorouter 将检查传入请求中是否存在 Zipkin header ,如果不存在则创建它们。

If the X-B3-TraceId and X-B3-SpanId HTTP headers are not present in the request, the Gorouter generates values for these and inserts the headers into the request forwarded to an application.

If the X-B3-TraceId and X-B3-SpanId HTTP headers are present in the request, the Gorouter forwards them unmodified.

https://docs.pivotal.io/pivotalcf/2-3/concepts/http-routing.html#zipkin-headers

您可以在此处看到它正在创建一个 64 位跟踪 ID。

https://github.com/cloudfoundry/gorouter/blob/master/handlers/zipkin.go#L49-L57

您可以通过发送 header X-B3-TraceIdX-B3-SpanId 集的请求来确认。在这种情况下,Gorouter 应该原封不动地转发它们。

例如:curl -v -H 'X-B3-TraceId: 5bfcb33c9d564481479f2c212ec08143' -H X-B3-SpanId: 5bfcb33c9d564481479f2c212ec08143' https://your-cool-app.com/test

关于spring - PCF 上的 128 位侦探跟踪 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53492240/

相关文章:

java - 在 Spring 应用程序中使用 SecurityContextHolder 的安全实用程序

java - 销毁名称为 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' 的 bean 的方法抛出异常

spring-boot - 无法在 zipkin UI 依赖项选项卡中查看任何 'dependencies'

mysql - SpringBoot Cloud Foundry 覆盖数据库池大小 - 通信链路故障

redis - 如何清理 cloudfoundry 托管的 redis?

java - 与restTemplate 集成测试侦探

spring-boot - 重写 Spring Cloud sleuth Trace Id 格式

java - hibernate 不读取 ehcache.xml 或不超时?

spring - 当 POST 参数位于 URL 中时,Spring 3 中如何处理 POST 参数?

node.js - Cloudfoundry 上的 Restify 'invalid ELF header'