From ca97dad7a249af42813510019003cd9bc784c481 Mon Sep 17 00:00:00 2001 From: Andrew Glaude Date: Mon, 12 Jun 2023 15:29:51 -0400 Subject: [PATCH] tracer: move reflect nil error check to WithError to never set a bad nil value --- ddtrace/tracer/option.go | 4 ++++ ddtrace/tracer/span.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ddtrace/tracer/option.go b/ddtrace/tracer/option.go index 9dcbd1adb6..47dbc7d4ca 100644 --- a/ddtrace/tracer/option.go +++ b/ddtrace/tracer/option.go @@ -15,6 +15,7 @@ import ( "net/url" "os" "path/filepath" + "reflect" "runtime" "strconv" "strings" @@ -892,6 +893,9 @@ func FinishTime(t time.Time) FinishOption { // err to set tags such as the error message, error type and stack trace. It has // no effect if the error is nil. func WithError(err error) FinishOption { + if err == nil || reflect.ValueOf(err).IsNil() { + return func(_ *ddtrace.FinishConfig) {} + } return func(cfg *ddtrace.FinishConfig) { cfg.Error = err } diff --git a/ddtrace/tracer/span.go b/ddtrace/tracer/span.go index 128f6666f4..e926d5eba9 100644 --- a/ddtrace/tracer/span.go +++ b/ddtrace/tracer/span.go @@ -424,7 +424,7 @@ func (s *span) Finish(opts ...ddtrace.FinishOption) { if !cfg.FinishTime.IsZero() { t = cfg.FinishTime.UnixNano() } - if cfg.Error != nil && !reflect.ValueOf(cfg.Error).IsNil() { + if cfg.Error != nil { s.Lock() s.setTagError(cfg.Error, errorConfig{ noDebugStack: cfg.NoDebugStack,