nohup ./jaeger-agent --reporter.grpc.host-port={{collectorRPCHostPort}} --agent.tags=token={{token}}
opentracing-contrib/goredis
.github.com/opentracing-contrib/goredis
v0.0.0-20190807091203-90a2649c5f87
cfg := &jaegerConfig.Configuration{ServiceName: clientServerName, // 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
func InitRedisConnector() error {redisClient = redis.NewUniversalClient(&redis.UniversalOptions{Addrs: []string{redisAddress},Password: redisPassword,DB: 0,})if err := redisClient.Ping().Err(); err != nil {log.Println("redisClient.Ping() error:", err.Error())return err}return nil}
func GetRedisDBConnector(ctx context.Context) redis.UniversalClient {client := apmgoredis.Wrap(redisClient).WithContext(ctx)return client}
package mainimport ("context""fmt""github.com/go-redis/redis"apmgoredis "github.com/opentracing-contrib/goredis""github.com/opentracing/opentracing-go""github.com/uber/jaeger-client-go"jaegerConfig "github.com/uber/jaeger-client-go/config""log""time")const (redisAddress = "127.0.0.1:6379"redisPassword = ""clientServerName = "redis-client-demo"testKey = "redis-demo-key"endPoint = "xxxxx:6831" // HTTP reporting addresstoken = "abc")func main() {cfg := &jaegerConfig.Configuration{ServiceName: clientServerName, // 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 configurationopentracing.SetGlobalTracer(tracer)defer closer.Close()if err != nil {panic(fmt.Sprintf("ERROR: fail init Jaeger: %v\\n", err))}InitRedisConnector()redisClient := GetRedisDBConnector(context.Background())redisClient.Set(testKey, "redis-client-demo", time.Duration(1000)*time.Second)redisClient.Get(testKey)}var (redisClient redis.UniversalClient)func GetRedisDBConnector(ctx context.Context) redis.UniversalClient {client := apmgoredis.Wrap(redisClient).WithContext(ctx)return client}func InitRedisConnector() error {redisClient = redis.NewUniversalClient(&redis.UniversalOptions{Addrs: []string{redisAddress},Password: redisPassword,DB: 0,})if err := redisClient.Ping().Err(); err != nil {log.Println("redisClient.Ping() error:", err.Error())return err}return nil}
Was this page helpful?