nohup ./jaeger-agent --reporter.grpc.host-port={{collectorRPCHostPort}} --agent.tags=token={{token}}
opentracing-contrib/go-grpc
埋点依赖。github.com/opentracing-contrib/go-grpc
v0.0.0-20210225150812-73cb765af46e
cfg := &jaegerConfig.Configuration{ServiceName: grpcServerName, //对其发起请求的的调用链,叫什么服务Sampler: &jaegerConfig.SamplerConfig{ //采样策略的配置,详情见4.1.1Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ //配置客户端如何上报trace信息,所有字段都是可选的LogSpans: true,LocalAgentHostPort: endPoint,},//Token配置Tags: []opentracing.Tag{ //设置tag,token等信息可存于此opentracing.Tag{Key: "token", Value: token}, //设置token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) //根据配置得到tracer
s := grpc.NewServer(grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))
// 在gRPC服务器处注册我们的服务pb.RegisterHelloTraceServer(s, &server{})if err := s.Serve(lis); err != nil {log.Fatalf("failed to serve: %v", err)}
// Copyright © 2019-2020 Tencent Co., Ltd.// This file is part of tencent project.// Do not copy, cite, or distribute without the express// permission from Cloud Monitor group.package grpcdemoimport ("context""fmt""github.com/opentracing/opentracing-go""github.com/uber/jaeger-client-go"jaegerConfig "github.com/uber/jaeger-client-go/config""log""net""github.com/opentracing-contrib/go-grpc""google.golang.org/grpc")const (// 服务名 服务唯一标示,服务指标聚合过滤依据。grpcServerName = "demo-grpc-server"serverPort = ":9090")// server is used to implement proto.HelloTraceServer.type server struct {UnimplementedHelloTraceServer}// SayHello implements proto.HelloTraceServerfunc (s *server) SayHello(ctx context.Context, in *TraceRequest) (*TraceResponse, error) {log.Printf("Received: %v", in.GetName())return &TraceResponse{Message: "Hello " + in.GetName()}, nil}// StartServerfunc StartServer() {cfg := &jaegerConfig.Configuration{ServiceName: grpcServerName, //对其发起请求的的调用链,叫什么服务Sampler: &jaegerConfig.SamplerConfig{ //采样策略的配置,详情见4.1.1Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ //配置客户端如何上报trace信息,所有字段都是可选的LogSpans: true,LocalAgentHostPort: endPoint,},//Token配置Tags: []opentracing.Tag{ //设置tag,token等信息可存于此opentracing.Tag{Key: "token", Value: token}, //设置token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) //根据配置得到tracerdefer closer.Close()if err != nil {panic(fmt.Sprintf("ERROR: fail init Jaeger: %v\\n", err))}lis, err := net.Listen("tcp", serverPort)if err != nil {log.Fatalf("failed to listen: %v", err)}s := grpc.NewServer(grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))// 在gRPC服务器处注册我们的服务RegisterHelloTraceServer(s, &server{})if err := s.Serve(lis); err != nil {log.Fatalf("failed to serve: %v", err)}}
opentracing-contrib/go-stdlib/nethttp
依赖。github.com/opentracing-contrib/go-stdlib/nethttp
v1.0.0
cfg := &jaegerConfig.Configuration{ServiceName: grpcClientName, //对其发起请求的的调用链,叫什么服务Sampler: &jaegerConfig.SamplerConfig{ //采样策略的配置,详情见4.1.1Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ //配置客户端如何上报trace信息,所有字段都是可选的LogSpans: true,LocalAgentHostPort: endPoint,},//Token配置Tags: []opentracing.Tag{ //设置tag,token等信息可存于此opentracing.Tag{Key: "token", Value: token}, //设置token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) //根据配置得到tracer
// 向服务端建立连接,配置拦截器conn, err := grpc.Dial(serverAddress, grpc.WithInsecure(), grpc.WithBlock(),grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)))
// Copyright © 2019-2020 Tencent Co., Ltd.// This file is part of tencent project.// Do not copy, cite, or distribute without the express// permission from Cloud Monitor group.package grpcdemoimport ("context""fmt""github.com/opentracing-contrib/go-grpc""github.com/opentracing/opentracing-go""github.com/uber/jaeger-client-go"jaegerConfig "github.com/uber/jaeger-client-go/config""google.golang.org/grpc""log""time")const (// 服务名 服务唯一标示,服务指标聚合过滤依据。grpcClientName = "demo-grpc-client"defaultName = "TAW Tracing"serverAddress = "localhost:9090"endPoint = "xxxxx:6831" // 本地agent地址token = "abc")// StartClientfunc StartClient() {cfg := &jaegerConfig.Configuration{ServiceName: grpcClientName, //对其发起请求的的调用链,叫什么服务Sampler: &jaegerConfig.SamplerConfig{ //采样策略的配置,详情见4.1.1Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ //配置客户端如何上报trace信息,所有字段都是可选的LogSpans: true,LocalAgentHostPort: endPoint,},//Token配置Tags: []opentracing.Tag{ //设置tag,token等信息可存于此opentracing.Tag{Key: "token", Value: token}, //设置token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) //根据配置得到tracerdefer closer.Close()if err != nil {panic(fmt.Sprintf("ERROR: fail init Jaeger: %v\\n", err))}// 向服务端建立链接,配置拦截器conn, err := grpc.Dial(serverAddress, grpc.WithInsecure(), grpc.WithBlock(),grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)))if err != nil {log.Fatalf("did not connect: %v", err)}defer conn.Close()//c := NewHelloTraceClient(conn)ctx, cancel := context.WithTimeout(context.Background(), time.Second)defer cancel()// 发起RPC调用r, err := c.SayHello(ctx, &TraceRequest{Name: defaultName})if err != nil {log.Fatalf("could not greet: %v", err)}log.Printf("RPC Client receive: %s", r.GetMessage())}
本页内容是否解决了您的问题?