Skip to content

Commit

Permalink
Merge branch 'master' into drop-old-go
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartnelson3 authored Jan 12, 2022
2 parents e480da5 + cfb2b83 commit 8197da7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,17 @@ func (s *Span) End() {
}
}
}
if !s.dropped() && len(s.stacktrace) == 0 &&
s.Duration >= s.stackFramesMinDuration {
switch s.stackFramesMinDuration {
case -1:
// Always set stacktrace
s.setStacktrace(1)
case 0:
// If s.stackFramesMinDuration == 0, we never set stacktrace.
default:
if !s.dropped() && len(s.stacktrace) == 0 &&
s.Duration >= s.stackFramesMinDuration {
s.setStacktrace(1)
}
}
// If this span has a parent span, lock it before proceeding to
// prevent deadlocking when concurrently ending parent and child.
Expand Down
33 changes: 33 additions & 0 deletions span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,39 @@ func TestStartExitSpan(t *testing.T) {
assert.True(t, span.IsExitSpan())
}

func TestFramesMinDurationSpecialCases(t *testing.T) {
tracer := apmtest.NewRecordingTracer()

// verify that no stacktraces are recorded
tracer.SetSpanFramesMinDuration(0)
tx := tracer.StartTransaction("name", "type")
span := tx.StartSpan("span", "span", nil)
span.End()
tx.End()

tracer.Flush(nil)
tracer.Close()

spans := tracer.Payloads().Spans
require.Len(t, spans, 1)
assert.Len(t, spans[0].Stacktrace, 0)

// verify that stacktraces are always recorded
tracer = apmtest.NewRecordingTracer()
defer tracer.Close()
tracer.SetSpanFramesMinDuration(-1)
tx = tracer.StartTransaction("name", "type")
span = tx.StartSpan("span2", "span2", nil)
span.End()
tx.End()

tracer.Flush(nil)

spans = tracer.Payloads().Spans
require.Len(t, spans, 1)
assert.NotEmpty(t, spans[0].Stacktrace)
}

func TestCompressSpanNonSiblings(t *testing.T) {
// Asserts that non sibling spans are not compressed.
tracer := apmtest.NewRecordingTracer()
Expand Down

0 comments on commit 8197da7

Please sign in to comment.