mirror of
https://github.com/redis/go-redis.git
synced 2025-07-29 17:41:15 +03:00
Optimize Otel instrumentation
This commit is contained in:
22
options.go
22
options.go
@ -15,7 +15,6 @@ import (
|
||||
"github.com/go-redis/redis/v8/internal"
|
||||
"github.com/go-redis/redis/v8/internal/pool"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// Limiter is the interface of a rate limiter or a circuit breaker.
|
||||
@ -292,20 +291,21 @@ func getUserPassword(u *url.URL) (string, string) {
|
||||
func newConnPool(opt *Options) *pool.ConnPool {
|
||||
return pool.NewConnPool(&pool.Options{
|
||||
Dialer: func(ctx context.Context) (net.Conn, error) {
|
||||
var conn net.Conn
|
||||
err := internal.WithSpan(ctx, "redis.dial", func(ctx context.Context, span trace.Span) error {
|
||||
ctx, span := internal.StartSpan(ctx, "redis.dial")
|
||||
defer span.End()
|
||||
|
||||
if span.IsRecording() {
|
||||
span.SetAttributes(
|
||||
attribute.String("db.connection_string", opt.Addr),
|
||||
)
|
||||
}
|
||||
|
||||
var err error
|
||||
conn, err = opt.Dialer(ctx, opt.Network, opt.Addr)
|
||||
if err != nil {
|
||||
_ = internal.RecordError(ctx, span, err)
|
||||
}
|
||||
return err
|
||||
})
|
||||
return conn, err
|
||||
cn, err := opt.Dialer(ctx, opt.Network, opt.Addr)
|
||||
if err != nil {
|
||||
return nil, internal.RecordError(ctx, span, err)
|
||||
}
|
||||
|
||||
return cn, nil
|
||||
},
|
||||
PoolSize: opt.PoolSize,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
|
Reference in New Issue
Block a user