Article From:


MicroThree trace interfaces are implemented through Wrapper.aswxray,opencensus,opentracing,The main concern here is opentracing, which has become an industry standard.


To introduce OpenTracing, you just need opentracing. NewClientWrapper to join Client or Server.

func NewClientWrapper(ot opentracing.Tracer) client.Wrapper {
    return func(c client.Client) client.Client {
        return &otWrapper{ot, c}

opentracing.NewClientWrapperMethod entry is the interface opentracing. Tracer for OpenTracing

type Tracer interface {
    StartSpan(operationName string, opts ...StartSpanOption) Span
    Inject(sm SpanContext, format interface{}, carrier interface{}) error
    Extract(format interface{}, carrier interface{}) (SpanContext, error)


Deploy a test jaeger, server address:, Agent default port is 5775.

[root@localhost jaeger]# ll
total 158444
-rwxr-xr-x 1 root root 14565068 Nov 16 19:35 example-hotrod
-rwxr-xr-x 1 root root 20387089 Nov 16 19:35 jaeger-agent
-rwxr-xr-x 1 root root 38456594 Nov 16 19:35 jaeger-all-in-one
-rwxr-xr-x 1 root root 29731462 Nov 16 19:35 jaeger-collector
-rwxr-xr-x 1 root root 25523281 Nov 16 19:35 jaeger-ingester
-rwxr-xr-x 1 root root 33563911 Nov 16 19:35 jaeger-query
-rwxr-xr-x 1 root root       43 Nov 16 19:36 run
-rw-r--r-- 1 root root     1939 Nov 16 19:36 x.log
[root@localhost jaeger]# cat run
nohup ./jaeger-all-in-one  >> x.log 2>&1 &

jaegerIt is a distributed tracing system, which implements the opentracing API standard. It is also Go Ecology and is a member of CNCF.

func TestJaeger(t *testing.T) {
    cfg := config.Configuration{
        ServiceName: "MicroTestService",//Custom service nameSampler: amp; config. Sampler Config {Type: "const",Param: 1,}Reporter: amp; config. Reporter Config {LogSpans: true,Buffer Flush Interval: 1 * time. Second,Local Agent HostPort:"//jaeger agent}}Tracer, close, err: = cfg. NewTracer ()If err! = nil {T.Error (ERR)Return}Defer closer.Close ()R: = mock. NewRegistry ()S:= selector. NewSelector (selector. Registry (r))C: = client. NewClient/ / set the selectorClient.Selector (s),//add the trace wrapperClient. Wrap (New Client Wrapper (t)Racer))Req: = C. NewRequest ("test. service", "Test. Method", "map [string] string {"FOO: "bar",}, client. WithContentType ("application/json")Var RSP map [string] interface {}C. Call (context. TODO (), req, rsp)T.Log (RSP)}

Browser access: can be foundMicroTestServiceAccess tracking

Leave a Reply

Your email address will not be published. Required fields are marked *