1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Add Tracestate into the SamplingResult struct (#1432)

* Add Tracestate into the SamplingResult struct

Add `trace.Tracestate` field into the SDK `trace.SamplingResult` struct.

Use ParentContext from SamplingParameters to return Tracestate in
`traceIDRatioSampler`, `alwaysOnSampler` and `alwaysOffSampler`.

Add a new test to check that Tracestate is passed.

* Updated CHANGELOG.md for #1432 PR

Added changes description for #1432.

* Update sdk/trace/sampling_test.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Andrei Ozerov
2021-01-06 22:09:48 +03:00
committed by GitHub
parent db06c8d1cb
commit 40f1c0039d
3 changed files with 64 additions and 5 deletions
+45
View File
@@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace"
)
@@ -189,3 +190,47 @@ func TestTraceIdRatioSamplesInclusively(t *testing.T) {
}
}
}
func TestTracestateIsPassed(t *testing.T) {
testCases := []struct {
name string
sampler Sampler
}{
{
"notSampled",
NeverSample(),
},
{
"sampled",
AlwaysSample(),
},
{
"parentSampled",
ParentBased(AlwaysSample()),
},
{
"parentNotSampled",
ParentBased(NeverSample()),
},
{
"traceIDRatioSampler",
TraceIDRatioBased(.5),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
traceState, err := trace.TraceStateFromKeyValues(label.String("k", "v"))
if err != nil {
t.Error(err)
}
parentCtx := trace.SpanContext{
TraceState: traceState,
}
params := SamplingParameters{ParentContext: parentCtx}
require.Equal(t, traceState, tc.sampler.ShouldSample(params).Tracestate, "TraceState is not equal")
})
}
}