Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions extra/redisotel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisotel

import (
"context"
"errors"
"fmt"
"net"
"sync"
Expand Down Expand Up @@ -271,9 +272,10 @@ func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook {

dur := time.Since(start)

attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+1)
attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+2)
attrs = append(attrs, mh.attrs...)
attrs = append(attrs, statusAttr(err))
attrs = append(attrs, cancelledAttr(err))

mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))
return conn, err
Expand All @@ -288,10 +290,11 @@ func (mh *metricsHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {

dur := time.Since(start)

attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+2)
attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+3)
attrs = append(attrs, mh.attrs...)
attrs = append(attrs, attribute.String("type", "command"))
attrs = append(attrs, statusAttr(err))
attrs = append(attrs, cancelledAttr(err))

mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))

Expand All @@ -309,10 +312,11 @@ func (mh *metricsHook) ProcessPipelineHook(

dur := time.Since(start)

attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+2)
attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+3)
attrs = append(attrs, mh.attrs...)
attrs = append(attrs, attribute.String("type", "pipeline"))
attrs = append(attrs, statusAttr(err))
attrs = append(attrs, cancelledAttr(err))

mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))

Expand All @@ -330,3 +334,10 @@ func statusAttr(err error) attribute.KeyValue {
}
return attribute.String("status", "ok")
}

func cancelledAttr(err error) attribute.KeyValue {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return attribute.Bool("canceled", true)
}
return attribute.Bool("canceled", false)
}
Loading