motan学习笔记 五 opentracing学习入门







opentracing是什么?

opentracing(http://opentracing.io/)  是分布式跟踪系统,当我们把系统拆成服务化,分布式系统的时候,查询一个问题,很可能需要多个登录多台机器。
opentracing 定义了一套api
通过提供平台无关、厂商无关的API,使得开发人员能够方便的添加(或更换)追踪系统的实现。OpenTracing正在为全球的分布式追踪,提供统一的概念和数据标准。


opentracing 在哪里有java版?

从github,下载java版本的分支( https://github.com/opentracing/opentracing-java)

从下面的图,可以看出api为定义模块,mock挡板 noop空实现  impl具体实现




opentracing 定义了哪些api?

span

一条消息,相当于一个打点信息,里面有两个重要的方法   finish 和 其他

finish 用来完成span的信息,并且用于提交 而其他方法用来组装span的数据

SpanContext


及传输的上下文,保存一些数据,一般loaclThread的,主要方法

Iterable<Map.Entry<String, String>> baggageItems();


Tracer

定义了两个方法,一个是往spancontext 插入参数,一个获取spancontext,相当于span集合

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <C> void inject(SpanContext spanContext, Format<C> format, C carrier);  
  2. <C> SpanContext extract(Format<C> format, C carrier);  

Format其实就是 定义的几个map  
[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. public interface Format<C> {  
  2.     final class Builtin<C> implements Format<C> {   
  3.         public final static Format<TextMap> TEXT_MAP = new Builtin<TextMap>();  
  4.     public final static Format<TextMap> HTTP_HEADERS = new Builtin<TextMap>();  
  5.         public final static Format<ByteBuffer> BINARY = new Builtin<ByteBuffer>();  
  6.     }  

SpanBuilder

顾名思义,builder模式,用来构建 span, 关键是start方法,构建成功

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. interface SpanBuilder extends SpanContext {  
  2.   
  3.       /** 
  4.        * A shorthand for addReference(References.CHILD_OF, parent). 
  5.        */  
  6.       SpanBuilder asChildOf(SpanContext parent);  
  7.   
  8.       /** 
  9.        * A shorthand for addReference(References.CHILD_OF, parent.context()). 
  10.        */  
  11.       SpanBuilder asChildOf(Span parent);  
  12.   
  13.       /** 
  14.        * Add a reference from the Span being built to a distinct (usually parent) Span. May be called multiple times to 
  15.        * represent multiple such References. 
  16.        * 
  17.        * @param referenceType the reference type, typically one of the constants defined in References 
  18.        * @param referencedContext the SpanContext being referenced; e.g., for a References.CHILD_OF referenceType, the 
  19.        *                          referencedContext is the parent 
  20.        * 
  21.        * @see io.opentracing.References 
  22.        */  
  23.       SpanBuilder addReference(String referenceType, SpanContext referencedContext);  
  24.   
  25.       /** Same as {@link Span#setTag(String, String)}, but for the span being built. */  
  26.       SpanBuilder withTag(String key, String value);  
  27.   
  28.       /** Same as {@link Span#setTag(String, String)}, but for the span being built. */  
  29.       SpanBuilder withTag(String key, boolean value);  
  30.   
  31.       /** Same as {@link Span#setTag(String, String)}, but for the span being built. */  
  32.       SpanBuilder withTag(String key, Number value);  
  33.   
  34.       /** Specify a timestamp of when the Span was started, represented in microseconds since epoch. */  
  35.       SpanBuilder withStartTimestamp(long microseconds);  
  36.   
  37.       /** Returns the started Span. */  
  38.       Span start();  
  39.   
  40.   }  
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值