Tweak otel span and attr names

This commit is contained in:
Vladimir Mihailenco 2020-11-15 14:30:27 +02:00
parent fa2e0da4e8
commit 13782c03d0
5 changed files with 11 additions and 12 deletions

View File

@ -24,7 +24,7 @@ func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.
ctx, span := tracer.Start(ctx, cmd.FullName()) ctx, span := tracer.Start(ctx, cmd.FullName())
span.SetAttributes( span.SetAttributes(
label.String("db.system", "redis"), label.String("db.system", "redis"),
label.String("redis.cmd", rediscmd.CmdString(cmd)), label.String("db.statement", rediscmd.CmdString(cmd)),
) )
return ctx, nil return ctx, nil
@ -49,8 +49,8 @@ func (TracingHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder
ctx, span := tracer.Start(ctx, "pipeline "+summary) ctx, span := tracer.Start(ctx, "pipeline "+summary)
span.SetAttributes( span.SetAttributes(
label.String("db.system", "redis"), label.String("db.system", "redis"),
label.Int("redis.num_cmd", len(cmds)), label.Int("db.redis.num_cmd", len(cmds)),
label.String("redis.cmds", cmdsString), label.String("db.statement", cmdsString),
) )
return ctx, nil return ctx, nil

View File

@ -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 { 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 { if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, err) 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( func (cn *Conn) WithWriter(
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error, ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
) 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 { if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, err) return internal.RecordError(ctx, err)
} }

View File

@ -11,7 +11,7 @@ import (
) )
func Sleep(ctx context.Context, dur time.Duration) error { 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) t := time.NewTimer(dur)
defer t.Stop() defer t.Stop()

View File

@ -293,11 +293,10 @@ func newConnPool(opt *Options) *pool.ConnPool {
return pool.NewConnPool(&pool.Options{ return pool.NewConnPool(&pool.Options{
Dialer: func(ctx context.Context) (net.Conn, error) { Dialer: func(ctx context.Context) (net.Conn, error) {
var conn net.Conn 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 var err error
span.SetAttributes( span.SetAttributes(
label.String("redis.network", opt.Network), label.String("db.connection_string", opt.Addr),
label.String("redis.addr", opt.Addr),
) )
conn, err = opt.Dialer(ctx, opt.Network, opt.Addr) conn, err = opt.Dialer(ctx, opt.Network, opt.Addr)
if err != nil { if err != nil {

View File

@ -225,7 +225,7 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
return cn, nil 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) return c.initConn(ctx, cn)
}) })
if err != nil { if err != nil {
@ -299,7 +299,7 @@ func (c *baseClient) releaseConn(ctx context.Context, cn *pool.Conn, err error)
func (c *baseClient) withConn( func (c *baseClient) withConn(
ctx context.Context, fn func(context.Context, *pool.Conn) error, ctx context.Context, fn func(context.Context, *pool.Conn) error,
) 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) cn, err := c.getConn(ctx)
if err != nil { if err != nil {
return err return err
@ -326,7 +326,7 @@ func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
attempt := attempt attempt := attempt
var retry bool 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 attempt > 0 {
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
return err return err