From 74b87ac9fd042a8187ba97a4e4aa85adf1f4328a Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Tue, 5 Mar 2024 14:40:10 +0800 Subject: [PATCH] chore: coding style (#3972) --- core/stores/redis/hook.go | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/core/stores/redis/hook.go b/core/stores/redis/hook.go index fca21498..18612b7b 100644 --- a/core/stores/redis/hook.go +++ b/core/stores/redis/hook.go @@ -83,6 +83,33 @@ func (h hook) ProcessPipelineHook(next red.ProcessPipelineHook) red.ProcessPipel } } +func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) (context.Context, func(err error)) { + tracer := trace.TracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, + spanName, + oteltrace.WithSpanKind(oteltrace.SpanKindClient), + ) + + cmdStrs := make([]string, 0, len(cmds)) + for _, cmd := range cmds { + cmdStrs = append(cmdStrs, cmd.Name()) + } + span.SetAttributes(redisCmdsAttributeKey.StringSlice(cmdStrs)) + + return ctx, func(err error) { + defer span.End() + + if err == nil || errors.Is(err, red.Nil) { + span.SetStatus(codes.Ok, "") + return + } + + span.SetStatus(codes.Error, err.Error()) + span.RecordError(err) + } +} + func formatError(err error) string { if err == nil || errors.Is(err, red.Nil) { return "" @@ -123,30 +150,3 @@ func logDuration(ctx context.Context, cmds []red.Cmder, duration time.Duration) } logx.WithContext(ctx).WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String()) } - -func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) (context.Context, func(err error)) { - tracer := trace.TracerFromContext(ctx) - - ctx, span := tracer.Start(ctx, - spanName, - oteltrace.WithSpanKind(oteltrace.SpanKindClient), - ) - - cmdStrs := make([]string, 0, len(cmds)) - for _, cmd := range cmds { - cmdStrs = append(cmdStrs, cmd.Name()) - } - span.SetAttributes(redisCmdsAttributeKey.StringSlice(cmdStrs)) - - return ctx, func(err error) { - defer span.End() - - if err == nil || errors.Is(err, red.Nil) { - span.SetStatus(codes.Ok, "") - return - } - - span.SetStatus(codes.Error, err.Error()) - span.RecordError(err) - } -}