sleuth propagation,span tag 及span类型

sleuth 里面有多种span,要注意之间并没有继承等关系,如:

  • public final class MutableSpan implements Cloneable,和brave及Tracing没有直接关联
  • Brace 的span,这个才可以和tracing 关联
  • 这两种span 都有tag 函数

propagation 是可以整个trace 生命周期都可以看到,但要注意zipkin 并不处理、显示内容,注意文档原文(Baggage是带前缀,旧版支持的propagation ):

  • Baggage versus Span Tags
    Baggage travels with the trace (every child span contains the baggage of its parent). Zipkin has no knowledge of baggage and does
    not receive that information.
  • Tags are attached to a specific span. In other words, they are presented only for that particular span.

实际还有一种特殊的span,在MutableSpan 上增加tag,会传递到下一个span(比如,被调用rest 服务),但不会传递到下下一个span(比如被调用rest服务再调用服务)

要在zipkin显示propagation的值,需要转为tag,如可以考虑增加一个FinishedSpanHandler 来处理,如下代码:

@Bean
	FinishedSpanHandler handlerOne() {
		return new FinishedSpanHandler() {
			@Override
			public boolean handle(TraceContext traceContext, MutableSpan span) {
				Map maps = ExtraFieldPropagation.getAll(traceContext);
				//brave.Span bravespan = tracer.currentSpan();
				
				maps.forEach((key,value)->{
					logger.info("Propagation key:" + key);
					span.tag(key, value);
				});

				//span.tag("key","v");
				//span.name("foo");
				return true; // keep this span
			}
		};
	}

你可能感兴趣的:(sleuth)