From 13782c03d0514a64b159dcbdd4c15709265dc1f3 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 15 Nov 2020 14:30:27 +0200 Subject: [PATCH] Tweak otel span and attr names --- extra/redisotel/redisotel.go | 6 +++--- internal/pool/conn.go | 4 ++-- internal/util.go | 2 +- options.go | 5 ++--- redis.go | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/extra/redisotel/redisotel.go b/extra/redisotel/redisotel.go index d0ab602b..61059c26 100644 --- a/extra/redisotel/redisotel.go +++ b/extra/redisotel/redisotel.go @@ -24,7 +24,7 @@ func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context. ctx, span := tracer.Start(ctx, cmd.FullName()) span.SetAttributes( label.String("db.system", "redis"), - label.String("redis.cmd", rediscmd.CmdString(cmd)), + label.String("db.statement", rediscmd.CmdString(cmd)), ) return ctx, nil @@ -49,8 +49,8 @@ func (TracingHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder ctx, span := tracer.Start(ctx, "pipeline "+summary) span.SetAttributes( label.String("db.system", "redis"), - label.Int("redis.num_cmd", len(cmds)), - label.String("redis.cmds", cmdsString), + label.Int("db.redis.num_cmd", len(cmds)), + label.String("db.statement", cmdsString), ) return ctx, nil diff --git a/internal/pool/conn.go b/internal/pool/conn.go index b930a908..08a20717 100644 --- a/internal/pool/conn.go +++ b/internal/pool/conn.go @@ -66,7 +66,7 @@ func (cn *Conn) RemoteAddr() net.Addr { } func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error { - return internal.WithSpan(ctx, "with_reader", func(ctx context.Context, span trace.Span) error { + return internal.WithSpan(ctx, "redis.with_reader", func(ctx context.Context, span trace.Span) error { if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil { return internal.RecordError(ctx, err) } @@ -80,7 +80,7 @@ func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(r func (cn *Conn) WithWriter( ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error, ) error { - return internal.WithSpan(ctx, "with_writer", func(ctx context.Context, span trace.Span) error { + return internal.WithSpan(ctx, "redis.with_writer", func(ctx context.Context, span trace.Span) error { if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil { return internal.RecordError(ctx, err) } diff --git a/internal/util.go b/internal/util.go index 9c861b0f..894382b8 100644 --- a/internal/util.go +++ b/internal/util.go @@ -11,7 +11,7 @@ import ( ) func Sleep(ctx context.Context, dur time.Duration) error { - return WithSpan(ctx, "sleep", func(ctx context.Context, span trace.Span) error { + return WithSpan(ctx, "time.Sleep", func(ctx context.Context, span trace.Span) error { t := time.NewTimer(dur) defer t.Stop() diff --git a/options.go b/options.go index b3d3196a..2b743c8f 100644 --- a/options.go +++ b/options.go @@ -293,11 +293,10 @@ 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, "dialer", func(ctx context.Context, span trace.Span) error { + err := internal.WithSpan(ctx, "redis.dialer", func(ctx context.Context, span trace.Span) error { var err error span.SetAttributes( - label.String("redis.network", opt.Network), - label.String("redis.addr", opt.Addr), + label.String("db.connection_string", opt.Addr), ) conn, err = opt.Dialer(ctx, opt.Network, opt.Addr) if err != nil { diff --git a/redis.go b/redis.go index f3b35838..efad7f13 100644 --- a/redis.go +++ b/redis.go @@ -225,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, span trace.Span) error { + err = internal.WithSpan(ctx, "redis.init_conn", func(ctx context.Context, span trace.Span) error { return c.initConn(ctx, cn) }) if err != nil { @@ -299,7 +299,7 @@ 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, span trace.Span) error { + return internal.WithSpan(ctx, "redis.with_conn", func(ctx context.Context, span trace.Span) error { cn, err := c.getConn(ctx) if err != nil { return err @@ -326,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, span trace.Span) error { + err := internal.WithSpan(ctx, "redis.process", func(ctx context.Context, span trace.Span) error { if attempt > 0 { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { return err