1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-30 04:40:41 +02:00

Deprecated the oteltest.TraceStateFromKeyValues function (#2122)

* Deprecated the oteltest.TraceStateFromKeyValues func

* Update changelog

* make precommit
This commit is contained in:
Tyler Yahn 2021-07-26 08:12:53 -07:00 committed by GitHub
parent ece1879fae
commit 7a624ac21c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 44 deletions

View File

@ -28,6 +28,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Deprecated
- The `TextMapCarrier` and `TextMapPropagator` from the `go.opentelemetry.io/otel/oteltest` package and their associated creation functions (`TextMapCarrier`, `NewTextMapPropagator`) are deprecated. (#2114)
- The `TraceStateFromKeyValues` function from the `go.opentelemetry.io/otel/oteltest` package is deprecated.
Use the `trace.ParseTraceState` function instead. (#2122)
### Removed

View File

@ -7,7 +7,6 @@ require (
github.com/google/go-cmp v0.5.6
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v1.0.0-RC1
go.opentelemetry.io/otel/oteltest v1.0.0-RC1
go.opentelemetry.io/otel/sdk v1.0.0-RC1
go.opentelemetry.io/otel/trace v1.0.0-RC1
go.opentelemetry.io/proto/otlp v0.9.0

View File

@ -19,8 +19,6 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/oteltest"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -205,7 +203,7 @@ func TestSpanData(t *testing.T) {
// March 31, 2020 5:01:26 1234nanos (UTC)
startTime := time.Unix(1585674086, 1234)
endTime := startTime.Add(10 * time.Second)
traceState, _ := oteltest.TraceStateFromKeyValues(attribute.String("key1", "val1"), attribute.String("key2", "val2"))
traceState, _ := trace.ParseTraceState("key1=val1,key2=val2")
spanData := tracetest.SpanStub{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},

View File

@ -10,7 +10,6 @@ replace (
require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v1.0.0-RC1
go.opentelemetry.io/otel/oteltest v1.0.0-RC1
go.opentelemetry.io/otel/sdk v1.0.0-RC1
go.opentelemetry.io/otel/trace v1.0.0-RC1
)

View File

@ -27,7 +27,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
@ -46,7 +45,7 @@ func TestExporter_ExportSpan(t *testing.T) {
now := time.Now()
traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10")
spanID, _ := trace.SpanIDFromHex("0102030405060708")
traceState, _ := oteltest.TraceStateFromKeyValues(attribute.String("key", "val"))
traceState, _ := trace.ParseTraceState("key=val")
keyValue := "value"
doubleValue := 123.456
resource := resource.NewSchemaless(attribute.String("rk1", "rv11"))

View File

@ -28,6 +28,8 @@ import (
// by definition from the W3C tracecontext specification, stores values as
// opaque strings. Therefore, it is not possible to decode the original value
// type from TraceState. Be sure to not use this outside of testing purposes.
//
// Deprecated: use trace.ParseTraceState instead.
func TraceStateFromKeyValues(kvs ...attribute.KeyValue) (trace.TraceState, error) {
if len(kvs) == 0 {
return trace.TraceState{}, nil

View File

@ -23,8 +23,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/trace"
)
@ -241,7 +239,7 @@ func TestTracestateIsPassed(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
traceState, err := oteltest.TraceStateFromKeyValues(attribute.String("k", "v"))
traceState, err := trace.ParseTraceState("k=v")
if err != nil {
t.Error(err)
}

View File

@ -63,9 +63,6 @@ var (
sc trace.SpanContext
handler = &storingHandler{}
k1, k2, k3 attribute.Key
kv1, kv2, kv3 attribute.KeyValue
)
func init() {
@ -77,13 +74,6 @@ func init() {
TraceFlags: 0x1,
})
k1 = attribute.Key("k1")
kv1 = k1.String("v1")
k2 = attribute.Key("k2")
kv2 = k2.String("v2")
k3 = attribute.Key("k3")
kv3 = k3.String("v3")
otel.SetErrorHandler(handler)
}
@ -354,7 +344,7 @@ func TestStartSpanWithParent(t *testing.T) {
t.Error(err)
}
ts, err := oteltest.TraceStateFromKeyValues(attribute.String("k", "v"))
ts, err := trace.ParseTraceState("k=v")
if err != nil {
t.Error(err)
}
@ -1625,17 +1615,20 @@ func (s stateSampler) Description() string {
// Check that a new span propagates the SamplerResult.TraceState
func TestSamplerTraceState(t *testing.T) {
mustTS := func(t trace.TraceState, err error) trace.TraceState { return t }
makeInserter := func(k attribute.KeyValue, prefix string) Sampler {
mustTS := func(ts trace.TraceState, err error) trace.TraceState {
require.NoError(t, err)
return ts
}
makeInserter := func(k, v, prefix string) Sampler {
return &stateSampler{
prefix: prefix,
f: func(t trace.TraceState) trace.TraceState { return mustTS(t.Insert(string(k.Key), k.Value.Emit())) },
f: func(t trace.TraceState) trace.TraceState { return mustTS(t.Insert(k, v)) },
}
}
makeDeleter := func(k attribute.Key, prefix string) Sampler {
makeDeleter := func(k, prefix string) Sampler {
return &stateSampler{
prefix: prefix,
f: func(t trace.TraceState) trace.TraceState { return t.Delete(string(k)) },
f: func(t trace.TraceState) trace.TraceState { return t.Delete(k) },
}
}
clearer := func(prefix string) Sampler {
@ -1656,55 +1649,55 @@ func TestSamplerTraceState(t *testing.T) {
{
name: "alwaysOn",
sampler: AlwaysSample(),
input: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
input: mustTS(trace.ParseTraceState("k1=v1")),
want: mustTS(trace.ParseTraceState("k1=v1")),
exportSpan: true,
},
{
name: "alwaysOff",
sampler: NeverSample(),
input: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
input: mustTS(trace.ParseTraceState("k1=v1")),
want: mustTS(trace.ParseTraceState("k1=v1")),
exportSpan: false,
},
{
name: "insertKeySampled",
sampler: makeInserter(kv2, "span"),
sampler: makeInserter("k2", "v2", "span"),
spanName: "span0",
input: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv2, kv1)),
input: mustTS(trace.ParseTraceState("k1=v1")),
want: mustTS(trace.ParseTraceState("k2=v2,k1=v1")),
exportSpan: true,
},
{
name: "insertKeyDropped",
sampler: makeInserter(kv2, "span"),
sampler: makeInserter("k2", "v2", "span"),
spanName: "nospan0",
input: mustTS(oteltest.TraceStateFromKeyValues(kv1)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv2, kv1)),
input: mustTS(trace.ParseTraceState("k1=v1")),
want: mustTS(trace.ParseTraceState("k2=v2,k1=v1")),
exportSpan: false,
},
{
name: "deleteKeySampled",
sampler: makeDeleter(k1, "span"),
sampler: makeDeleter("k1", "span"),
spanName: "span0",
input: mustTS(oteltest.TraceStateFromKeyValues(kv1, kv2)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv2)),
input: mustTS(trace.ParseTraceState("k1=v1,k2=v2")),
want: mustTS(trace.ParseTraceState("k2=v2")),
exportSpan: true,
},
{
name: "deleteKeyDropped",
sampler: makeDeleter(k1, "span"),
sampler: makeDeleter("k1", "span"),
spanName: "nospan0",
input: mustTS(oteltest.TraceStateFromKeyValues(kv1, kv2, kv3)),
want: mustTS(oteltest.TraceStateFromKeyValues(kv2, kv3)),
input: mustTS(trace.ParseTraceState("k1=v1,k2=v2,k3=v3")),
want: mustTS(trace.ParseTraceState("k2=v2,k3=v3")),
exportSpan: false,
},
{
name: "clearer",
sampler: clearer("span"),
spanName: "span0",
input: mustTS(oteltest.TraceStateFromKeyValues(kv1, kv3)),
want: mustTS(oteltest.TraceStateFromKeyValues()),
input: mustTS(trace.ParseTraceState("k1=v1,k3=v3")),
want: mustTS(trace.ParseTraceState("")),
exportSpan: true,
},
}