【GO】jeager
安装
docker pull jaegertracing/all-in-one:latest
docker run \
--rm \
--name jaeger \
-d \
-p6831:6831/udp \
-p16686:16686 \
-p14268:14268 \
jaegertracing/all-in-one:latest
// --rm 可能导致报错自,报错如下,删除参数即可
// Error response from daemon: Cannot update container dd7608a4303ea3f961367222267c0b4b220a9207e18fb8699f4bb8f2469f525f: Restart policy cannot be updated because AutoRemove is enabled for the container
- 查看容器及设置自启动
docker ps -a
docker container update --restart=always 容器id
- 访问前先开放16686端口
http://xxx.xxx.xxx.xxx:16686
入门
import "github.com/opentracing/opentracing-go"
- 示例
package main
import (
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
"time"
)
func main() {
cfg := jaegercfg.Configuration{
Sampler: &jaegercfg.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
Reporter: &jaegercfg.ReporterConfig{
LogSpans: true,
LocalAgentHostPort: "xxx.xxx.xxx.xxx:6831",
},
ServiceName: "ff-user-test-web",
}
tracer, closer, err := cfg.NewTracer(jaegercfg.Logger(jaeger.StdLogger))
if err != nil {
panic(err)
}
opentracing.SetGlobalTracer(tracer) // 通过三方 github.com/opentracing/opentracing-go 将 tracer 设置为全局 opentracing.GlobalTracer()
defer closer.Close()
// 这里使用全局的 tracer ,将原生 tracer.StartSpan 替换成 opentracing.StartSpan 即可
parentSpan := opentracing.StartSpan("funmain1")
span1 := opentracing.StartSpan("fun11", opentracing.ChildOf(parentSpan.Context()))
time.Sleep(time.Millisecond * 500)
span1.Finish()
time.Sleep(time.Millisecond * 100)
span2 := opentracing.StartSpan("fun22", opentracing.ChildOf(span1.Context()))
time.Sleep(time.Millisecond * 1000)
span2.Finish()
parentSpan.Finish()
}
grpc融合
- 下载包,不要直接安装,因为需要修改源码,如果安装了包使用下边命令清除
go clean -i github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc
gin融合
作者:小魁jking
出处:https://www.cnblogs.com/wangjinkui/
版权:本文版权归作者和博客园共有
转载:欢迎转载,但未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任
出处:https://www.cnblogs.com/wangjinkui/
版权:本文版权归作者和博客园共有
转载:欢迎转载,但未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任