2020-03-25 23:47:17 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2020-02-03 20:22:52 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package trace_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-05-02 14:17:11 +02:00
|
|
|
"go.opentelemetry.io/otel/api/trace"
|
|
|
|
|
2020-02-03 20:22:52 +02:00
|
|
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAlwaysParentSampleWithParentSampled(t *testing.T) {
|
|
|
|
sampler := sdktrace.AlwaysParentSample()
|
2020-05-02 14:23:09 +02:00
|
|
|
traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
2020-05-02 14:17:11 +02:00
|
|
|
spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
|
|
|
|
parentCtx := trace.SpanContext{
|
2020-02-03 20:22:52 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
2020-05-05 19:41:54 +02:00
|
|
|
TraceFlags: trace.FlagsSampled,
|
2020-02-03 20:22:52 +02:00
|
|
|
}
|
2020-03-10 17:25:11 +02:00
|
|
|
if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled {
|
|
|
|
t.Error("Sampling decision should be RecordAndSampled")
|
2020-02-03 20:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlwaysParentSampleWithParentNotSampled(t *testing.T) {
|
|
|
|
sampler := sdktrace.AlwaysParentSample()
|
2020-05-02 14:23:09 +02:00
|
|
|
traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
|
2020-05-02 14:17:11 +02:00
|
|
|
spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
|
|
|
|
parentCtx := trace.SpanContext{
|
2020-02-03 20:22:52 +02:00
|
|
|
TraceID: traceID,
|
|
|
|
SpanID: spanID,
|
|
|
|
}
|
2020-03-10 17:25:11 +02:00
|
|
|
if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.NotRecord {
|
|
|
|
t.Error("Sampling decision should be NotRecord")
|
2020-02-03 20:22:52 +02:00
|
|
|
}
|
|
|
|
}
|