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

tracer: dual sampling, make sure priorities -1 and 2 are handled #137

Merged
merged 3 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
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: 6 additions & 6 deletions tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ func (s *Span) Tracer() *Tracer {
return s.tracer
}

// SetSamplingPriority sets the sampling priority.
// Default is 0, any higher value is interpreted as a hint on
// how interesting this span is, and should be kept by the backend.
// SetSamplingPriority sets the sampling priority. Possible values are:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we provide constants for these values?

// -1: The user asked not to keep the trace;
// 0: The sampler automatically decided not to keep the trace;
// 1: The sampler automatically decided to keep the trace;
// 2: The user asked to keep the trace.
func (s *Span) SetSamplingPriority(priority int) {
if priority >= 0 {
s.SetMetric(samplingPriorityKey, float64(priority))
}
s.SetMetric(samplingPriorityKey, float64(priority))
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM. Maybe add the -1 case to the method's comment?

}

// HasSamplingPriority returns true if sampling priority is set.
Expand Down
40 changes: 9 additions & 31 deletions tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,37 +265,15 @@ func TestSpanSamplingPriority(t *testing.T) {
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())

span.SetSamplingPriority(0)
assert.Equal(0.0, span.Metrics["_sampling_priority_v1"], "key has been deleted")
assert.Equal(0, span.GetSamplingPriority(), "by default, sampling priority is 0")
childSpan = tracer.NewChildSpan("my.child", span)
assert.Equal(span.Metrics["_sampling_priority_v1"], childSpan.Metrics["_sampling_priority_v1"])
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())

span.SetSamplingPriority(-1)
assert.Equal(0.0, span.Metrics["_sampling_priority_v1"], "key has been deleted")
assert.Equal(0, span.GetSamplingPriority(), "by default, sampling priority can't be negative")
childSpan = tracer.NewChildSpan("my.child", span)
assert.Equal(span.Metrics["_sampling_priority_v1"], childSpan.Metrics["_sampling_priority_v1"])
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())

span.SetSamplingPriority(1)
assert.Equal(1.0, span.Metrics["_sampling_priority_v1"], "sampling priority is now 1")
assert.Equal(1, span.GetSamplingPriority(), "sampling priority is now 1")
childSpan = tracer.NewChildSpan("my.child", span)
assert.Equal(span.Metrics["_sampling_priority_v1"], childSpan.Metrics["_sampling_priority_v1"])
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())

span.SetSamplingPriority(42)
assert.Equal(42.0, span.Metrics["_sampling_priority_v1"], "sampling priority works for values above 1")
assert.Equal(42, span.GetSamplingPriority(), "sampling priority works for values above 1")
childSpan = tracer.NewChildSpan("my.child", span)
assert.Equal(span.Metrics["_sampling_priority_v1"], childSpan.Metrics["_sampling_priority_v1"])
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())
for _, priority := range []int{-1, 0, 1, 2, 999} {
span.SetSamplingPriority(priority)
assert.True(span.HasSamplingPriority())
assert.Equal(priority, span.GetSamplingPriority())
childSpan = tracer.NewChildSpan("my.child", span)
assert.Equal(span.Metrics["_sampling_priority_v1"], childSpan.Metrics["_sampling_priority_v1"])
assert.Equal(span.HasSamplingPriority(), childSpan.HasSamplingPriority())
assert.Equal(span.GetSamplingPriority(), childSpan.GetSamplingPriority())
}
}

type boomError struct{}
Expand Down