Skip to content

Commit

Permalink
tracer: Check for nil interface types in span.Finish(WithError())
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgajg1134 committed Jun 12, 2023
1 parent b9a86a0 commit 2a0f38c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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 {
if cfg.Error != nil && !reflect.ValueOf(cfg.Error).IsNil() {
s.Lock()
s.setTagError(cfg.Error, errorConfig{
noDebugStack: cfg.NoDebugStack,
Expand Down
22 changes: 22 additions & 0 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@ func TestSpanFinishWithError(t *testing.T) {
assert.NotEmpty(span.Meta[ext.ErrorStack])
}

type MyError struct {
msg string
}

func (e *MyError) Error() string {
return e.msg
}

func TestSpanFinishWithErrorNilCustomError(t *testing.T) {
assert := assert.New(t)

var err error
var myError *MyError
myError = nil
err = myError

span := newBasicSpan("web.request")
span.Finish(WithError(err))

assert.Equal(int32(0), span.Error)
}

func TestSpanFinishWithErrorNoDebugStack(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 2a0f38c

Please sign in to comment.