diff --git a/CHANGELOG.md b/CHANGELOG.md index 95048204..8e3cc0ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Rename `go.opentelemetry.io/otel/api/metric.ConfigureInstrument` to `NewInstrumentConfig` and `go.opentelemetry.io/otel/api/metric.ConfigureMeter` to `NewMeterConfig`. - Move the `go.opentelemetry.io/otel/api/unit` package to `go.opentelemetry.io/otel/unit`. (#1185) +- Renamed `SamplingDecision` values to comply with OpenTelemetry specification change. (#1192) ### Fixed diff --git a/sdk/trace/sampling.go b/sdk/trace/sampling.go index 84222983..8e4f76d1 100644 --- a/sdk/trace/sampling.go +++ b/sdk/trace/sampling.go @@ -39,14 +39,21 @@ type SamplingParameters struct { Links []api.Link } -// SamplingDecision indicates whether a span is recorded and sampled. +// SamplingDecision indicates whether a span is dropped, recorded and/or sampled. type SamplingDecision uint8 // Valid sampling decisions const ( - NotRecord SamplingDecision = iota - Record - RecordAndSampled + // Drop will not record the span and all attributes/events will be dropped + Drop SamplingDecision = iota + + // Record indicates the span's `IsRecording() == true`, but `Sampled` flag + // *must not* be set + RecordOnly + + // RecordAndSample has span's `IsRecording() == true` and `Sampled` flag + // *must* be set + RecordAndSample ) // SamplingResult conveys a SamplingDecision and a set of Attributes. @@ -63,9 +70,9 @@ type traceIDRatioSampler struct { func (ts traceIDRatioSampler) ShouldSample(p SamplingParameters) SamplingResult { x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1 if x < ts.traceIDUpperBound { - return SamplingResult{Decision: RecordAndSampled} + return SamplingResult{Decision: RecordAndSample} } - return SamplingResult{Decision: NotRecord} + return SamplingResult{Decision: Drop} } func (ts traceIDRatioSampler) Description() string { @@ -95,7 +102,7 @@ func TraceIDRatioBased(fraction float64) Sampler { type alwaysOnSampler struct{} func (as alwaysOnSampler) ShouldSample(p SamplingParameters) SamplingResult { - return SamplingResult{Decision: RecordAndSampled} + return SamplingResult{Decision: RecordAndSample} } func (as alwaysOnSampler) Description() string { @@ -113,7 +120,7 @@ func AlwaysSample() Sampler { type alwaysOffSampler struct{} func (as alwaysOffSampler) ShouldSample(p SamplingParameters) SamplingResult { - return SamplingResult{Decision: NotRecord} + return SamplingResult{Decision: Drop} } func (as alwaysOffSampler) Description() string { diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 636590e8..f2a2be65 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -33,8 +33,8 @@ func TestParentBasedDefaultLocalParentSampled(t *testing.T) { SpanID: spanID, TraceFlags: api.FlagsSampled, } - if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != RecordAndSampled { - t.Error("Sampling decision should be RecordAndSampled") + if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != RecordAndSample { + t.Error("Sampling decision should be RecordAndSample") } } @@ -46,8 +46,8 @@ func TestParentBasedDefaultLocalParentNotSampled(t *testing.T) { TraceID: traceID, SpanID: spanID, } - if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != NotRecord { - t.Error("Sampling decision should be NotRecord") + if sampler.ShouldSample(SamplingParameters{ParentContext: parentCtx}).Decision != Drop { + t.Error("Sampling decision should be Drop") } } @@ -55,13 +55,13 @@ func TestParentBasedWithNoParent(t *testing.T) { params := SamplingParameters{} sampler := ParentBased(AlwaysSample()) - if sampler.ShouldSample(params).Decision != RecordAndSampled { - t.Error("Sampling decision should be RecordAndSampled") + if sampler.ShouldSample(params).Decision != RecordAndSample { + t.Error("Sampling decision should be RecordAndSample") } sampler = ParentBased(NeverSample()) - if sampler.ShouldSample(params).Decision != NotRecord { - t.Error("Sampling decision should be NotRecord") + if sampler.ShouldSample(params).Decision != Drop { + t.Error("Sampling decision should be Drop") } } @@ -77,28 +77,28 @@ func TestParentBasedWithSamplerOptions(t *testing.T) { WithLocalParentSampled(NeverSample()), false, true, - NotRecord, + Drop, }, { "localParentNotSampled", WithLocalParentNotSampled(AlwaysSample()), false, false, - RecordAndSampled, + RecordAndSample, }, { "remoteParentSampled", WithRemoteParentSampled(NeverSample()), true, true, - NotRecord, + Drop, }, { "remoteParentNotSampled", WithRemoteParentNotSampled(AlwaysSample()), true, false, - RecordAndSampled, + RecordAndSample, }, } @@ -126,13 +126,13 @@ func TestParentBasedWithSamplerOptions(t *testing.T) { ) switch tc.expectedDecision { - case RecordAndSampled: + case RecordAndSample: if sampler.ShouldSample(params).Decision != tc.expectedDecision { - t.Error("Sampling decision should be RecordAndSampled") + t.Error("Sampling decision should be RecordAndSample") } - case NotRecord: + case Drop: if sampler.ShouldSample(params).Decision != tc.expectedDecision { - t.Error("Sampling decision should be NotRecord") + t.Error("Sampling decision should be Drop") } } }) @@ -181,8 +181,8 @@ func TestTraceIdRatioSamplesInclusively(t *testing.T) { traceID := idg.NewTraceID() params := SamplingParameters{TraceID: traceID} - if samplerLo.ShouldSample(params).Decision == RecordAndSampled { - require.Equal(t, RecordAndSampled, samplerHi.ShouldSample(params).Decision, + if samplerLo.ShouldSample(params).Decision == RecordAndSample { + require.Equal(t, RecordAndSample, samplerHi.ShouldSample(params).Decision, "%s sampled but %s did not", samplerLo.Description(), samplerHi.Description()) } } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index a7092c68..a388c674 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -426,7 +426,7 @@ func makeSamplingDecision(data samplingData) SamplingResult { Attributes: data.attributes, Links: data.links, }) - if sampled.Decision == RecordAndSampled { + if sampled.Decision == RecordAndSample { spanContext.TraceFlags |= apitrace.FlagsSampled } else { spanContext.TraceFlags &^= apitrace.FlagsSampled @@ -434,7 +434,7 @@ func makeSamplingDecision(data samplingData) SamplingResult { return sampled } if data.parent.TraceFlags&apitrace.FlagsSampled != 0 { - return SamplingResult{Decision: RecordAndSampled} + return SamplingResult{Decision: RecordAndSample} } - return SamplingResult{Decision: NotRecord} + return SamplingResult{Decision: Drop} } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 6194a438..8273a81a 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -138,9 +138,9 @@ type testSampler struct { func (ts *testSampler) ShouldSample(p SamplingParameters) SamplingResult { ts.callCount++ ts.t.Logf("called sampler for name %q", p.Name) - decision := NotRecord + decision := Drop if strings.HasPrefix(p.Name, ts.prefix) { - decision = RecordAndSampled + decision = RecordAndSample } return SamplingResult{Decision: decision, Attributes: []label.KeyValue{label.Int("callCount", ts.callCount)}} }