Skip to content

Commit

Permalink
introduce a samler fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
gbbr committed Dec 24, 2018
1 parent dce65e5 commit 1730727
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ddtrace/tracer/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const knuthFactor = uint64(1111111111111111111)

// Sample returns true if the given span should be sampled.
func (r *rateSampler) Sample(spn ddtrace.Span) bool {
if r.rate == 1 {
// fast path
return true
}
s, ok := spn.(*span)
if !ok {
return false
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestRateSampler(t *testing.T) {
assert.True(NewRateSampler(1).Sample(newBasicSpan("test")))
assert.False(NewRateSampler(0).Sample(newBasicSpan("test")))
assert.False(NewRateSampler(0).Sample(newBasicSpan("test")))
assert.False(NewRateSampler(1).Sample(internal.NoopSpan{}))
assert.False(NewRateSampler(0.99).Sample(internal.NoopSpan{}))
}

func TestRateSamplerSetting(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,8 @@ func (t *tracer) sample(span *span) {
return
}
sampler := t.config.sampler
sampled := sampler.Sample(span)
span.context.drop = !sampled
if !sampled {
if !sampler.Sample(span) {
span.context.drop = true
return
}
if rs, ok := sampler.(RateSampler); ok && rs.Rate() < 1 {
Expand Down

0 comments on commit 1730727

Please sign in to comment.