nohup ./jaeger-agent --reporter.grpc.host-port={{collectorRPCHostPort}} --agent.tags=token={{token}}
opentracing-contrib/go-grpc
on the server.github.com/opentracing-contrib/go-grpc
v0.0.0-20210225150812-73cb765af46e
cfg := &jaegerConfig.Configuration{ServiceName: grpcServerName, // Call trace of the target service. Enter the service name.Sampler: &jaegerConfig.SamplerConfig{ // Sampling policy configuration. See section 4.1.1 for details.Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ // Configure how the client reports trace information. All fields are optional.LogSpans: true,LocalAgentHostPort: endPoint,},// Token configurationTags: []opentracing.Tag{ // Set the tag, where information such as token can be stored.opentracing.Tag{Key: "token", Value: token}, // Set the token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) // Get the tracer based on the configuration
s := grpc.NewServer(grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))
// Register our service with the gRPC serverpb.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 (// Service name, which is the unique identifier of the service and the basis for service metric aggregation and filtering.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, // Call trace of the target service. Enter the service name.Sampler: &jaegerConfig.SamplerConfig{ // Sampling policy configuration. See section 4.1.1 for details.Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ // Configure how the client reports trace information. All fields are optional.LogSpans: true,LocalAgentHostPort: endPoint,},// Token configurationTags: []opentracing.Tag{ // Set the tag, where information such as token can be stored.opentracing.Tag{Key: "token", Value: token}, // Set the token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) // Get the tracer based on the configurationdefer 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)))// Register our service with the gRPC serverRegisterHelloTraceServer(s, &server{})if err := s.Serve(lis); err != nil {log.Fatalf("failed to serve: %v", err)}}
opentracing-contrib/go-stdlib/nethttp
dependency.github.com/opentracing-contrib/go-stdlib/nethttp
v1.0.0
cfg := &jaegerConfig.Configuration{ServiceName: grpcClientName, // Call trace of the target service. Enter the service name.Sampler: &jaegerConfig.SamplerConfig{ // Sampling policy configuration. See section 4.1.1 for details.Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ // Configure how the client reports trace information. All fields are optional.LogSpans: true,LocalAgentHostPort: endPoint,},// Token configurationTags: []opentracing.Tag{ // Set the tag, where information such as token can be stored.opentracing.Tag{Key: "token", Value: token}, // Set the token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) // Get the tracer based on the configuration
// Establish a connection to the server to configure the interceptorconn, 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 (// Service name, which is the unique identifier of the service and the basis for service metric aggregation and filtering.grpcClientName = "demo-grpc-client"defaultName = "TAW Tracing"serverAddress = "localhost:9090"endPoint = "xxxxx:6831" // Local agent addresstoken = "abc")// StartClientfunc StartClient() {cfg := &jaegerConfig.Configuration{ServiceName: grpcClientName, // Call trace of the target service. Enter the service name.Sampler: &jaegerConfig.SamplerConfig{ // Sampling policy configuration. See section 4.1.1 for details.Type: "const",Param: 1,},Reporter: &jaegerConfig.ReporterConfig{ // Configure how the client reports trace information. All fields are optional.LogSpans: true,LocalAgentHostPort: endPoint,},// Token configurationTags: []opentracing.Tag{ // Set the tag, where information such as token can be stored.opentracing.Tag{Key: "token", Value: token}, // Set the token},}tracer, closer, err := cfg.NewTracer(jaegerConfig.Logger(jaeger.StdLogger)) // Get the tracer based on the configurationdefer closer.Close()if err != nil {panic(fmt.Sprintf("ERROR: fail init Jaeger: %v\\n", err))}// Establish a connection to the server to configure the interceptorconn, 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()// Make an RPC callr, 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())}
Was this page helpful?