chore: optimize code (#1818)

Signed-off-by: chenquan <chenquan.dev@gmail.com>
This commit is contained in:
chen quan
2022-04-23 09:02:04 -05:00
committed by GitHub
parent 095b603788
commit 22b157bb6c
3 changed files with 14 additions and 17 deletions

View File

@@ -19,7 +19,6 @@ const spanName = "redis"
var (
startTimeKey = contextKey("startTime")
spanKey = contextKey("span")
durationHook = hook{tracer: otel.GetTracerProvider().Tracer(trace.TraceName)}
)
@@ -96,17 +95,10 @@ func logDuration(ctx context.Context, cmd red.Cmder, duration time.Duration) {
}
func (h hook) startSpan(ctx context.Context) context.Context {
ctx, span := h.tracer.Start(ctx, spanName)
return context.WithValue(ctx, spanKey, span)
ctx, _ = h.tracer.Start(ctx, spanName)
return ctx
}
func (h hook) endSpan(ctx context.Context) {
spanVal := ctx.Value(spanKey)
if spanVal == nil {
return
}
if span, ok := spanVal.(tracestd.Span); ok {
span.End()
}
tracestd.SpanFromContext(ctx).End()
}