Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle special cases for span frames min duration #1188

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines +359 to +369
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been squished into a single conditional, and I'm happy to do so. This just seemed to be more easy to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Maybe we can revisit when we get to #1142

}
// If this span has a parent span, lock it before proceeding to
// prevent deadlocking when concurrently ending parent and child.
Expand Down
32 changes: 32 additions & 0 deletions span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,38 @@ 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()
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.Len(t, spans[0].Stacktrace, 4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just check it's non-empty? The Go runtime or testing package might add more frames in the future.

}

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