OpenTracing开放式分布式追踪规范,常见实现:jaeger和zipkin
docker启动一个实例:
docker run -p 5775:5775/udp -p 16686:16686 -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 14268:14268 jaegertracing/all-in-one:latest
go
来一个普通的go程序
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-lib/metrics"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/uber/jaeger-client-go/config"
)
var (
tracerServer opentracing.Tracer
)
func TraceInit(serviceName string, samplerType string, samplerParam float64) (opentracing.Tracer, io.Closer) {
cfg := &config.Configuration{
ServiceName: serviceName,
Sampler: &config.SamplerConfig{
Type: samplerType,
Param: samplerParam,
},
Reporter: &config.ReporterConfig{
LocalAgentHostPort: "192.168.100.21:6831",
LogSpans: true,
},
}
tracer, closer, err := cfg.NewTracer(config.Logger(jaeger.StdLogger), config.Metrics(metrics.NullFactory))
if err != nil {
panic(fmt.Sprintf("Init failed: %v\n", err))
}
return tracer, closer
}
func GetListProc(w http.ResponseWriter, req *http.Request) {
spanCtx, _ := tracerServer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header))
span :&#