Skip to content

Commit

Permalink
add span logs for redis spans with error (#3045)
Browse files Browse the repository at this point in the history
Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Apr 26, 2024
1 parent 6ee45b1 commit 9570e4f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ratelimit/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ func (c *clusterLimitRedis) Allow(ctx context.Context, clearText string) bool {
failed := err != nil
if failed {
allow = !c.failClosed
setError(span)
c.logError("Failed to determine if operation is allowed: %v", err)
msgFmt := "Failed to determine if operation is allowed: %v"
setError(span, fmt.Sprintf(msgFmt, err))
c.logError(msgFmt, err)
}
if span != nil {
span.SetTag("allowed", allow)
Expand Down Expand Up @@ -207,9 +208,10 @@ func (c *clusterLimitRedis) Delta(clearText string) time.Duration {
return d
}

func setError(span opentracing.Span) {
func setError(span opentracing.Span, msg string) {
if span != nil {
ext.Error.Set(span, true)
span.LogKV("log", msg)
}
}

Expand All @@ -233,7 +235,7 @@ func (c *clusterLimitRedis) oldest(ctx context.Context, clearText string) (time.
res, err := c.ringClient.ZRangeByScoreWithScoresFirst(ctx, key, 0.0, float64(now.UnixNano()), 0, 1)

if err != nil {
setError(span)
setError(span, fmt.Sprintf("Failed to execute ZRangeByScoreWithScoresFirst: %v", err))
return time.Time{}, err
}

Expand All @@ -243,13 +245,14 @@ func (c *clusterLimitRedis) oldest(ctx context.Context, clearText string) (time.

s, ok := res.(string)
if !ok {
setError(span)
return time.Time{}, errors.New("failed to evaluate redis data")
msg := "failed to evaluate redis data"
setError(span, msg)
return time.Time{}, errors.New(msg)
}

oldest, err := strconv.ParseInt(s, 10, 64)
if err != nil {
setError(span)
setError(span, fmt.Sprintf("failed to convert value to int64: %v", err))
return time.Time{}, fmt.Errorf("failed to convert value to int64: %w", err)
}

Expand Down

0 comments on commit 9570e4f

Please sign in to comment.