Skip to content

Commit

Permalink
ddtrace/tracer: add noDebugStack to config in when setting error tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoledanuwidjaja committed Apr 12, 2021
1 parent 8ee7a3c commit ce49089
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func (s *span) SetTag(key string, value interface{}) {
}
switch key {
case ext.Error:
s.setTagError(value, &errorConfig{})
s.setTagError(value, &errorConfig{
noDebugStack: s.noDebugStack,
})
return
}
if v, ok := value.(bool); ok {
Expand Down
25 changes: 25 additions & 0 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,31 @@ func TestSpanSetTag(t *testing.T) {
assert.Equal("false", span.Meta["some.other.bool"])
}

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

span1 := newBasicSpan("web.request")
span1.setTagError(errors.New("error value with no trace"), &errorConfig{noDebugStack: true})
assert.Equal(int32(1), span1.Error)
assert.Equal("error value with no trace", span1.Meta[ext.ErrorMsg])
assert.Equal("*errors.errorString", span1.Meta[ext.ErrorType])
assert.Empty(span1.Meta[ext.ErrorStack])

span2 := newBasicSpan("web.request")
span2.setTagError(errors.New("error value with trace"), &errorConfig{noDebugStack: false})
assert.Equal(int32(1), span2.Error)
assert.Equal("error value with trace", span2.Meta[ext.ErrorMsg])
assert.Equal("*errors.errorString", span2.Meta[ext.ErrorType])
assert.NotEmpty(span2.Meta[ext.ErrorStack])

span3 := newBasicSpan("web.request")
span3.setTagError(errors.New("error value with trace, no given config"), &errorConfig{})
assert.Equal(int32(1), span3.Error)
assert.Equal("error value with trace, no given config", span3.Meta[ext.ErrorMsg])
assert.Equal("*errors.errorString", span3.Meta[ext.ErrorType])
assert.NotEmpty(span3.Meta[ext.ErrorStack])
}

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

Expand Down
15 changes: 14 additions & 1 deletion ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func TestTracerSpanGlobalTags(t *testing.T) {
assert.Equal("value", child.Meta["key"])
}

func TestTracerNoDebugStack(t *testing.T) {
func TestTracerNoDebugStackFinish(t *testing.T) {
assert := assert.New(t)
tracer := newTracer(WithDebugStack(false))
s := tracer.StartSpan("web.request").(*span)
Expand All @@ -464,6 +464,19 @@ func TestTracerNoDebugStack(t *testing.T) {
assert.Empty(s.Meta[ext.ErrorStack])
}

func TestTracerNoDebugStackFinishSetTag(t *testing.T) {
assert := assert.New(t)
tracer := newTracer(WithDebugStack(false))
s := tracer.StartSpan("web.request").(*span)
err := errors.New("error value with no trace")
s.SetTag(ext.Error, err)

assert.Equal(int32(1), s.Error)
assert.Equal("error value with no trace", s.Meta[ext.ErrorMsg])
assert.Equal("*errors.errorString", s.Meta[ext.ErrorType])
assert.Empty(s.Meta[ext.ErrorStack])
}

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

Expand Down

0 comments on commit ce49089

Please sign in to comment.