mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-06 23:16:14 +02:00
Update Sampler descriptions (#511)
* update always and never sample descriptions * fix typo * rename always on / off sampler files, structs and variables to match Co-authored-by: Rahul Patel <rahulpa@google.com>
This commit is contained in:
parent
cba1664b46
commit
638b865c90
@ -19,17 +19,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
neverSamplerDescription = "NeverSampleSampler"
|
alwaysOffSamplerDescription = "AlwaysOffSampler"
|
||||||
)
|
)
|
||||||
|
|
||||||
var neverSampledecision = Decision{Sampled: false}
|
var alwaysOffSamplerDecision = Decision{Sampled: false}
|
||||||
|
|
||||||
type neverSampleSampler struct{}
|
type alwaysOffSampler struct{}
|
||||||
|
|
||||||
// ShouldSample implements Sampler interface.
|
// ShouldSample implements Sampler interface.
|
||||||
// It always returns a Decision with Sampled value set to false
|
// It always returns a Decision with Sampled value set to false
|
||||||
// and with Attributes set to an empty slice.
|
// and with Attributes set to an empty slice.
|
||||||
func (ns neverSampleSampler) ShouldSample(
|
func (ns alwaysOffSampler) ShouldSample(
|
||||||
_ core.SpanContext,
|
_ core.SpanContext,
|
||||||
_ bool,
|
_ bool,
|
||||||
_ core.TraceID,
|
_ core.TraceID,
|
||||||
@ -39,17 +39,17 @@ func (ns neverSampleSampler) ShouldSample(
|
|||||||
_ []core.KeyValue,
|
_ []core.KeyValue,
|
||||||
_ []Link,
|
_ []Link,
|
||||||
) Decision {
|
) Decision {
|
||||||
return neverSampledecision
|
return alwaysOffSamplerDecision
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description implements Sampler interface.
|
// Description implements Sampler interface.
|
||||||
// It returns the description of this sampler.
|
// It returns the description of this sampler.
|
||||||
func (ns neverSampleSampler) Description() string {
|
func (ns alwaysOffSampler) Description() string {
|
||||||
return neverSamplerDescription
|
return alwaysOffSamplerDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Sampler = neverSampleSampler{}
|
var _ Sampler = alwaysOffSampler{}
|
||||||
|
|
||||||
func NeverSampleSampler() Sampler {
|
func AlwaysOffSampler() Sampler {
|
||||||
return neverSampleSampler{}
|
return alwaysOffSampler{}
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNeverSamperShouldSample(t *testing.T) {
|
func TestNeverSamperShouldSample(t *testing.T) {
|
||||||
gotD := NeverSampleSampler().ShouldSample(
|
gotD := AlwaysOffSampler().ShouldSample(
|
||||||
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
|
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
|
||||||
wantD := Decision{Sampled: false}
|
wantD := Decision{Sampled: false}
|
||||||
if diff := cmp.Diff(wantD, gotD); diff != "" {
|
if diff := cmp.Diff(wantD, gotD); diff != "" {
|
||||||
@ -31,9 +31,9 @@ func TestNeverSamperShouldSample(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNeverSamplerDescription(t *testing.T) {
|
func TestAlwaysOffSamplerDescription(t *testing.T) {
|
||||||
gotDesc := NeverSampleSampler().Description()
|
gotDesc := AlwaysOffSampler().Description()
|
||||||
wantDesc := neverSamplerDescription
|
wantDesc := alwaysOffSamplerDescription
|
||||||
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
|
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
|
||||||
t.Errorf("Description: +got, -want%v", diff)
|
t.Errorf("Description: +got, -want%v", diff)
|
||||||
}
|
}
|
@ -19,17 +19,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
alwaysSamplerDescription = "AlwaysSampleSampler"
|
alwaysOnSamplerDescription = "AlwaysOnSampler"
|
||||||
)
|
)
|
||||||
|
|
||||||
var alwaysSampleDecision = Decision{Sampled: true}
|
var alwaysOnSamplerDecision = Decision{Sampled: true}
|
||||||
|
|
||||||
type alwaysSampleSampler struct{}
|
type alwaysOnSampler struct{}
|
||||||
|
|
||||||
// ShouldSample implements Sampler interface.
|
// ShouldSample implements Sampler interface.
|
||||||
// It always returns a Decision with Sampled value set to true
|
// It always returns a Decision with Sampled value set to true
|
||||||
// and with Attributes set to an empty slice.
|
// and with Attributes set to an empty slice.
|
||||||
func (as alwaysSampleSampler) ShouldSample(
|
func (as alwaysOnSampler) ShouldSample(
|
||||||
_ core.SpanContext,
|
_ core.SpanContext,
|
||||||
_ bool,
|
_ bool,
|
||||||
_ core.TraceID,
|
_ core.TraceID,
|
||||||
@ -39,17 +39,17 @@ func (as alwaysSampleSampler) ShouldSample(
|
|||||||
_ []core.KeyValue,
|
_ []core.KeyValue,
|
||||||
_ []Link,
|
_ []Link,
|
||||||
) Decision {
|
) Decision {
|
||||||
return alwaysSampleDecision
|
return alwaysOnSamplerDecision
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description implements Sampler interface.
|
// Description implements Sampler interface.
|
||||||
// It returns the description of this sampler.
|
// It returns the description of this sampler.
|
||||||
func (as alwaysSampleSampler) Description() string {
|
func (as alwaysOnSampler) Description() string {
|
||||||
return alwaysSamplerDescription
|
return alwaysOnSamplerDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Sampler = alwaysSampleSampler{}
|
var _ Sampler = alwaysOnSampler{}
|
||||||
|
|
||||||
func AlwaysSampleSampler() Sampler {
|
func AlwaysOnSampler() Sampler {
|
||||||
return alwaysSampleSampler{}
|
return alwaysOnSampler{}
|
||||||
}
|
}
|
@ -22,8 +22,8 @@ import (
|
|||||||
"go.opentelemetry.io/otel/api/core"
|
"go.opentelemetry.io/otel/api/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShouldSample(t *testing.T) {
|
func TestAlwaysOnSamplerShouldSample(t *testing.T) {
|
||||||
gotD := AlwaysSampleSampler().ShouldSample(
|
gotD := AlwaysOnSampler().ShouldSample(
|
||||||
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
|
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
|
||||||
wantD := Decision{Sampled: true}
|
wantD := Decision{Sampled: true}
|
||||||
if diff := cmp.Diff(wantD, gotD); diff != "" {
|
if diff := cmp.Diff(wantD, gotD); diff != "" {
|
||||||
@ -31,9 +31,9 @@ func TestShouldSample(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDescription(t *testing.T) {
|
func TestAlwaysOnSamplerDescription(t *testing.T) {
|
||||||
gotDesc := AlwaysSampleSampler().Description()
|
gotDesc := AlwaysOnSampler().Description()
|
||||||
wantDesc := alwaysSamplerDescription
|
wantDesc := alwaysOnSamplerDescription
|
||||||
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
|
if diff := cmp.Diff(wantDesc, gotDesc); diff != "" {
|
||||||
t.Errorf("Description: +got, -want%v", diff)
|
t.Errorf("Description: +got, -want%v", diff)
|
||||||
}
|
}
|
@ -79,7 +79,7 @@ func (ps probabilitySampler) Description() string {
|
|||||||
|
|
||||||
// ProbabilitySampler samples a given fraction of traces. Fractions >= 1 will
|
// ProbabilitySampler samples a given fraction of traces. Fractions >= 1 will
|
||||||
// always sample. If the parent span is sampled, then it's child spans will
|
// always sample. If the parent span is sampled, then it's child spans will
|
||||||
// automatically be sampled. Fractions <0 are treated as zero, but spans may
|
// automatically be sampled. Fractions < 0 are treated as zero, but spans may
|
||||||
// still be sampled if their parent is.
|
// still be sampled if their parent is.
|
||||||
func ProbabilitySampler(fraction float64) Sampler {
|
func ProbabilitySampler(fraction float64) Sampler {
|
||||||
if fraction >= 1 {
|
if fraction >= 1 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user