Skip to content

Commit

Permalink
tracer: move reflect nil error check to WithError to never set a bad …
Browse files Browse the repository at this point in the history
…nil value
  • Loading branch information
ajgajg1134 committed Jun 12, 2023
1 parent 2a0f38c commit ca97dad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/url"
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ca97dad

Please sign in to comment.