Skip to content

Commit 48d9756

Browse files
committed
add handler stack
1 parent 662db1d commit 48d9756

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ddtrace/ext/tags.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ const (
8787
// ErrorType specifies the error type.
8888
ErrorType = "error.type"
8989

90-
// ErrorStack specifies the stack dump.
90+
// ErrorStack specifies the stack dump when the error is thrown.
9191
ErrorStack = "error.stack"
9292

93+
// ErrorHandlingStack specifies the stack dump when the error is captured.
94+
ErrorHandlingStack = "error.handling.stack"
95+
9396
// ErrorDetails holds details about an error which implements a formatter.
9497
ErrorDetails = "error.details"
9598

ddtrace/tracer/span.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,15 @@ func (s *Span) setTagError(value interface{}, cfg errorConfig) {
441441
s.setMeta(ext.ErrorDetails, fmt.Sprintf("%+v", v))
442442
if !cfg.noDebugStack {
443443
s.setMeta(ext.ErrorStack, err.Format())
444+
s.setMeta(ext.ErrorHandlingStack, takeStacktrace(cfg.stackFrames, cfg.stackSkip))
444445
}
445446
return
446447
}
447448
if !cfg.noDebugStack {
448-
s.setMeta(ext.ErrorStack, takeStacktrace(cfg.stackFrames, cfg.stackSkip))
449+
telemetry.Count(telemetry.NamespaceTracers, "errorstack.source", []string{"source:takeStacktrace"}).Submit(1)
450+
stack := takeStacktrace(cfg.stackFrames, cfg.stackSkip)
451+
s.setMeta(ext.ErrorStack, stack)
452+
s.setMeta(ext.ErrorHandlingStack, stack)
449453
}
450454
case nil:
451455
// no error
@@ -463,7 +467,6 @@ const defaultStackLength = 32
463467
// takeStacktrace takes a stack trace of maximum n entries, skipping the first skip entries.
464468
// If n is 0, up to 20 entries are retrieved.
465469
func takeStacktrace(n, skip uint) string {
466-
telemetry.Count(telemetry.NamespaceTracers, "errorstack.source", []string{"source:takeStacktrace"}).Submit(1)
467470
now := time.Now()
468471
defer func() {
469472
dur := float64(time.Since(now))

ddtrace/tracer/span_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,10 @@ func TestErrorStack(t *testing.T) {
797797
assert.NotEqual("", stack)
798798
assert.Contains(stack, "tracer.TestErrorStack")
799799
assert.Contains(stack, "tracer.createErrorTrace")
800+
801+
handlingStack := span.meta[ext.ErrorHandlingStack]
802+
assert.NotEqual("", handlingStack)
803+
assert.NotEqual(stack, handlingStack)
800804
span.Finish()
801805
})
802806

@@ -817,6 +821,10 @@ func TestErrorStack(t *testing.T) {
817821
assert.NotEqual("", stack)
818822
assert.Contains(stack, "tracer.TestErrorStack")
819823
assert.NotContains(stack, "tracer.createTestError") // this checks our old behavior
824+
825+
handlingStack := span.meta[ext.ErrorHandlingStack]
826+
assert.NotEqual("", handlingStack)
827+
assert.Equal(stack, handlingStack)
820828
span.Finish()
821829
})
822830
}
@@ -978,7 +986,6 @@ func TestSpanErrorStackMetrics(t *testing.T) {
978986
}
979987

980988
assert.Equal(0.0, telemetryClient.Count(telemetry.NamespaceTracers, "errorstack.source", []string{"source:takeStacktrace"}).Get())
981-
assert.Equal(0.0, telemetryClient.Distribution(telemetry.NamespaceTracers, "errorstack.duration", []string{"source:takeStacktrace"}).Get())
982989

983990
assert.Equal(5.0, telemetryClient.Count(telemetry.NamespaceTracers, "errorstack.source", []string{"source:TracerError"}).Get())
984991
if !windows {

0 commit comments

Comments
 (0)