mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
otel: add RemoteAddr
This commit is contained in:
15
redis.go
15
redis.go
@ -8,6 +8,8 @@ import (
|
||||
"github.com/go-redis/redis/v8/internal"
|
||||
"github.com/go-redis/redis/v8/internal/pool"
|
||||
"github.com/go-redis/redis/v8/internal/proto"
|
||||
"go.opentelemetry.io/otel/api/trace"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
)
|
||||
|
||||
// Nil reply returned by Redis when key does not exist.
|
||||
@ -223,7 +225,7 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
|
||||
return cn, nil
|
||||
}
|
||||
|
||||
err = internal.WithSpan(ctx, "init_conn", func(ctx context.Context) error {
|
||||
err = internal.WithSpan(ctx, "init_conn", func(ctx context.Context, span trace.Span) error {
|
||||
return c.initConn(ctx, cn)
|
||||
})
|
||||
if err != nil {
|
||||
@ -297,11 +299,18 @@ func (c *baseClient) releaseConn(ctx context.Context, cn *pool.Conn, err error)
|
||||
func (c *baseClient) withConn(
|
||||
ctx context.Context, fn func(context.Context, *pool.Conn) error,
|
||||
) error {
|
||||
return internal.WithSpan(ctx, "with_conn", func(ctx context.Context) error {
|
||||
return internal.WithSpan(ctx, "with_conn", func(ctx context.Context, span trace.Span) error {
|
||||
cn, err := c.getConn(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if span.IsRecording() {
|
||||
if remoteAddr := cn.RemoteAddr(); remoteAddr != nil {
|
||||
span.SetAttributes(label.String("net.peer.ip", remoteAddr.String()))
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
c.releaseConn(ctx, cn, err)
|
||||
}()
|
||||
@ -317,7 +326,7 @@ func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
|
||||
attempt := attempt
|
||||
|
||||
var retry bool
|
||||
err := internal.WithSpan(ctx, "process", func(ctx context.Context) error {
|
||||
err := internal.WithSpan(ctx, "process", func(ctx context.Context, span trace.Span) error {
|
||||
if attempt > 0 {
|
||||
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user