Skip to content

Commit

Permalink
ddtrace/tracer: Add normalization of span duration
Browse files Browse the repository at this point in the history
  • Loading branch information
piochelepiotr committed Aug 5, 2021
1 parent 63dea35 commit bebc4d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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) {
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)
var statusCode uint32
if sc, ok := s.Meta["http.status_code"]; ok && sc != "" {
if c, err := strconv.Atoi(sc); err == nil {
Expand Down
16 changes: 15 additions & 1 deletion 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)
expected := span{
Service: "testservice",
}
assert.Equal(t, expected, actual)
})
}

func BenchmarkSetTagMetric(b *testing.B) {
span := newBasicSpan("bench.span")
keys := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down Expand Up @@ -671,4 +685,4 @@ type stringer struct{}

func (s *stringer) String() string {
return "string"
}
}

0 comments on commit bebc4d9

Please sign in to comment.