【问题标题】:Is it possible to change name of variable 'traceId' in Sleuth?是否可以在 Sleuth 中更改变量“traceId”的名称?
【发布时间】:2019-10-04 07:41:39
【问题描述】:

我阅读了 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);
}

【问题讨论】:

    标签: spring spring-cloud-sleuth zipkin opentracing


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您可以使用此迁移文档将 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-24
        • 2012-07-03
        • 1970-01-01
        • 2017-10-20
        • 2018-10-12
        • 2016-08-28
        • 2019-06-28
        • 1970-01-01
        相关资源
        最近更新 更多