0

我阅读了 Sleuth 文档,但没有找到有关更改默认参数名称“traceId”或“spanId”的信息。是否可以不添加额外的字段?

@Override
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {
    Span currentSpan = this.tracer.currentSpan();
    if (currentSpan == null) {
        chain.doFilter(request, response);
        return;
    }

    currentSpan.customizer().tag("correlationId", currentSpan.context().spanIdString());

    chain.doFilter(request, response);
}
4

2 回答 2

0

您必须创建自己的Propagationbean 实现。默认值为B3Propagation. 您可以在此处查看默认实现https://github.com/openzipkin/brave/blob/5.8.0/brave/src/main/java/brave/propagation/B3Propagation.java

于 2019-10-04T07:53:07.780 回答
-1

您可以使用此迁移文档将 slueth traceid 重命名为其他任何内容。该文档允许您通过创建 bean 装饰器将 traceId 重命名为其他任何内容

 @Bean ScopeDecorator legacyIds() {
  return MDCScopeDecorator.newBuilder()
                         .clear()
                         .add(SingleCorrelationField.newBuilder(BaggageFields.TRACE_ID)
                                                    .name("X-B3-TraceId").build())
                         .add(SingleCorrelationField.newBuilder(BaggageFields.PARENT_ID)
                                                    .name("X-B3-ParentSpanId").build())
                         .add(SingleCorrelationField.newBuilder(BaggageFields.SPAN_ID)
                                                    .name("X-B3-SpanId").build())
                       .add(SingleCorrelationField.newBuilder(BaggageFields.SAMPLED)
                                                    .name("X-Span-Export").build())
                         .build();
}

https://github.com/spring-cloud/spring-cloud-sleuth/wiki/Spring-Cloud-Sleuth-3.0-Migration-Guide#x-b3--mdc-fields-names-are-no-longer-set

于 2021-10-27T06:49:35.773 回答