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

ddtrace/tracer: Add normalization of span duration #973

Merged
merged 7 commits into from
Sep 1, 2021
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
7 changes: 7 additions & 0 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,16 @@ func (s *span) finish(finishTime int64) {
s.context.finish()
}

func normalizeSpan(s *span) {
gbbr marked this conversation as resolved.
Show resolved Hide resolved
if s.Duration < 0 {
s.Duration = 0
}
}

// newAggregableSpan creates a new summary for the span s, within an application
// version version.
func newAggregableSpan(s *span, cfg *config) *aggregableSpan {
normalizeSpan(s)
gbbr marked this conversation as resolved.
Show resolved Hide resolved
var statusCode uint32
if sc, ok := s.Meta["http.status_code"]; ok && sc != "" {
if c, err := strconv.Atoi(sc); err == nil {
Expand Down
14 changes: 14 additions & 0 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,20 @@ func TestSpanLog(t *testing.T) {
})
}

func TestNormalizeSpan(t *testing.T) {
t.Run("negativeduration", func(t *testing.T) {
actual := span{
Service: "testservice",
Duration: -1,
}
normalizeSpan(&actual)
gbbr marked this conversation as resolved.
Show resolved Hide resolved
expected := span{
Service: "testservice",
}
assert.Equal(t, expected, actual)
})
}

func BenchmarkSetTagMetric(b *testing.B) {
span := newBasicSpan("bench.span")
keys := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down