From ece1879fae1bcea6d32f94fd8f6d174c3e118a6b Mon Sep 17 00:00:00 2001 From: Nelson Ghezzi Date: Mon, 26 Jul 2021 15:06:41 +0000 Subject: [PATCH 1/3] Removed dropped link's attributes field from API package (#2118) * Removed DroppedAttributeCount field from Link struct * Reintroduced DroppedAttributeCount with a wrapper struct * Added Link type in otel/sdk package and used it instead of Trace API equivalent * Added changelog entry * Linting fix in changelog * Deleted duplicated changelog section added by mistake * Expanded changelog entry and moved it under the 'Added' section * Explicitly mentioned otel/trace library in changelog entry under 'Removed' section to avoid ambiguity --- CHANGELOG.md | 4 +++ exporters/jaeger/jaeger_test.go | 4 +-- .../otlptrace/internal/otlptracetest/data.go | 2 +- .../otlptrace/internal/tracetransform/span.go | 2 +- .../internal/tracetransform/span_test.go | 8 +++-- sdk/trace/link.go | 34 +++++++++++++++++++ sdk/trace/snapshot.go | 4 +-- sdk/trace/span.go | 18 +++++----- sdk/trace/trace_test.go | 18 +++++----- sdk/trace/tracetest/span.go | 6 ++-- trace/trace.go | 4 --- 11 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 sdk/trace/link.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 16cff070c06..cdfa4ea2a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added the `WithRetry` option to the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` package. This option is a replacement for the removed `WithMaxAttempts` and `WithBackoff` options. (#2095) - Added API `LinkFromContext` to return Link which encapsulates SpanContext from provided context and also encapsulates attributes. (#2115) +- Added a new `Link` type under the SDK `otel/sdk/trace` package that counts the number of attributes that were dropped for surpassing the `AttributePerLinkCountLimit` configured in the Span's `SpanLimits`. + This new type replaces the equal-named API `Link` type found in the `otel/trace` package for most usages within the SDK. + For example, instances of this type are now returned by the `Links()` function of `ReadOnlySpan`s provided in places like the `OnEnd` function of `SpanProcessor` implementations. (#2118) ### Changed @@ -35,6 +38,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Removed the `WithMaxAttempts` and `WithBackoff` options from the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` package. The retry logic of the package has been updated to match the `otlptracegrpc` package and accordingly a `WithRetry` option is added that should be used instead. (#2095) - Removed metrics test package `go.opentelemetry.io/otel/sdk/export/metric/metrictest`. (#2105) +- Removed `DroppedAttributeCount` field from `otel/trace.Link` struct. (#2118) ### Fixed diff --git a/exporters/jaeger/jaeger_test.go b/exporters/jaeger/jaeger_test.go index 4db4a36ddef..b9844b7d2f7 100644 --- a/exporters/jaeger/jaeger_test.go +++ b/exporters/jaeger/jaeger_test.go @@ -219,7 +219,7 @@ func Test_spanSnapshotToThrift(t *testing.T) { Name: "/foo", StartTime: now, EndTime: now, - Links: []trace.Link{ + Links: []sdktrace.Link{ { SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ TraceID: linkTraceID, @@ -311,7 +311,7 @@ func Test_spanSnapshotToThrift(t *testing.T) { TraceID: traceID, SpanID: parentSpanID, }), - Links: []trace.Link{ + Links: []sdktrace.Link{ { SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ TraceID: linkTraceID, diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/internal/otlptracetest/data.go index 71708cd7393..cf6142e01db 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/data.go @@ -47,7 +47,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { EndTime: time.Date(2020, time.December, 0, 20, 24, 0, 0, time.UTC), Attributes: []attribute.KeyValue{}, Events: []tracesdk.Event{}, - Links: []trace.Link{}, + Links: []tracesdk.Link{}, Status: tracesdk.Status{Code: codes.Ok}, DroppedAttributes: 0, DroppedEvents: 0, diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index d6ac6377ed2..d9f0831092c 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -146,7 +146,7 @@ func status(status codes.Code, message string) *tracepb.Status { } // links transforms span Links to OTLP span links. -func links(links []trace.Link) []*tracepb.Span_Link { +func links(links []tracesdk.Link) []*tracepb.Span_Link { if len(links) == 0 { return nil } diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 62b7cc161f7..d220d770ab3 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -120,12 +120,12 @@ func TestNilLinks(t *testing.T) { } func TestEmptyLinks(t *testing.T) { - assert.Nil(t, links([]trace.Link{})) + assert.Nil(t, links([]tracesdk.Link{})) } func TestLinks(t *testing.T) { attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} - l := []trace.Link{ + l := []tracesdk.Link{ {}, { SpanContext: trace.SpanContext{}, @@ -234,7 +234,7 @@ func TestSpanData(t *testing.T) { }, }, }, - Links: []trace.Link{ + Links: []tracesdk.Link{ { SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ TraceID: trace.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, @@ -244,6 +244,7 @@ func TestSpanData(t *testing.T) { Attributes: []attribute.KeyValue{ attribute.String("LinkType", "Parent"), }, + DroppedAttributeCount: 0, }, { SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ @@ -254,6 +255,7 @@ func TestSpanData(t *testing.T) { Attributes: []attribute.KeyValue{ attribute.String("LinkType", "Child"), }, + DroppedAttributeCount: 0, }, }, Status: tracesdk.Status{ diff --git a/sdk/trace/link.go b/sdk/trace/link.go new file mode 100644 index 00000000000..19cfea4ba45 --- /dev/null +++ b/sdk/trace/link.go @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// +// 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 // import "go.opentelemetry.io/otel/sdk/trace" + +import ( + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" +) + +// Link is the relationship between two Spans. The relationship can be within +// the same Trace or across different Traces. +type Link struct { + // SpanContext of the linked Span. + SpanContext trace.SpanContext + + // Attributes describe the aspects of the link. + Attributes []attribute.KeyValue + + // DroppedAttributeCount is the number of attributes that were not + // recorded due to configured limits being reached. + DroppedAttributeCount int +} diff --git a/sdk/trace/snapshot.go b/sdk/trace/snapshot.go index 847617a382b..68670bb0b54 100644 --- a/sdk/trace/snapshot.go +++ b/sdk/trace/snapshot.go @@ -34,7 +34,7 @@ type snapshot struct { endTime time.Time attributes []attribute.KeyValue events []Event - links []trace.Link + links []Link status Status childSpanCount int droppedAttributeCount int @@ -87,7 +87,7 @@ func (s snapshot) Attributes() []attribute.KeyValue { } // Links returns all the links the span has to other spans. -func (s snapshot) Links() []trace.Link { +func (s snapshot) Links() []Link { return s.links } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 722f354762f..5200fa59b7a 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -55,7 +55,7 @@ type ReadOnlySpan interface { // Attributes returns the defining attributes of the span. Attributes() []attribute.KeyValue // Links returns all the links the span has to other spans. - Links() []trace.Link + Links() []Link // Events returns all the events that occurred within in the spans // lifetime. Events() []Event @@ -386,11 +386,11 @@ func (s *span) Attributes() []attribute.KeyValue { } // Links returns the links of this span. -func (s *span) Links() []trace.Link { +func (s *span) Links() []Link { s.mu.Lock() defer s.mu.Unlock() if len(s.links.queue) == 0 { - return []trace.Link{} + return []Link{} } return s.interfaceArrayToLinksArray() } @@ -435,13 +435,15 @@ func (s *span) addLink(link trace.Link) { s.mu.Lock() defer s.mu.Unlock() + var droppedAttributeCount int + // Discard over limited attributes if len(link.Attributes) > s.spanLimits.AttributePerLinkCountLimit { - link.DroppedAttributeCount = len(link.Attributes) - s.spanLimits.AttributePerLinkCountLimit + droppedAttributeCount = len(link.Attributes) - s.spanLimits.AttributePerLinkCountLimit link.Attributes = link.Attributes[:s.spanLimits.AttributePerLinkCountLimit] } - s.links.add(link) + s.links.add(Link{link.SpanContext, link.Attributes, droppedAttributeCount}) } // DroppedAttributes returns the number of attributes dropped by the span @@ -514,10 +516,10 @@ func (s *span) snapshot() ReadOnlySpan { return &sd } -func (s *span) interfaceArrayToLinksArray() []trace.Link { - linkArr := make([]trace.Link, 0) +func (s *span) interfaceArrayToLinksArray() []Link { + linkArr := make([]Link, 0) for _, value := range s.links.queue { - linkArr = append(linkArr, value.(trace.Link)) + linkArr = append(linkArr, value.(Link)) } return linkArr } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 4bf1116108b..e7e2084c883 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -656,10 +656,10 @@ func TestLinks(t *testing.T) { sc1 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}}) sc2 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}}) - links := []trace.Link{ - {SpanContext: sc1, Attributes: []attribute.KeyValue{k1v1}}, - {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2, k3v3}}, - } + l1 := trace.Link{SpanContext: sc1, Attributes: []attribute.KeyValue{k1v1}} + l2 := trace.Link{SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2, k3v3}} + + links := []trace.Link{l1, l2} span := startSpan(tp, "Links", trace.WithLinks(links...)) got, err := endSpan(te, span) @@ -674,7 +674,7 @@ func TestLinks(t *testing.T) { }), parent: sc.WithRemote(true), name: "span0", - links: links, + links: []Link{{l1.SpanContext, l1.Attributes, 0}, {l2.SpanContext, l2.Attributes, 0}}, spanKind: trace.SpanKindInternal, instrumentationLibrary: instrumentation.Library{Name: "Links"}, } @@ -715,9 +715,9 @@ func TestLinksOverLimit(t *testing.T) { }), parent: sc.WithRemote(true), name: "span0", - links: []trace.Link{ - {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2}}, - {SpanContext: sc3, Attributes: []attribute.KeyValue{k3v3}}, + links: []Link{ + {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2}, DroppedAttributeCount: 0}, + {SpanContext: sc3, Attributes: []attribute.KeyValue{k3v3}, DroppedAttributeCount: 0}, }, droppedLinkCount: 1, spanKind: trace.SpanKindInternal, @@ -1585,7 +1585,7 @@ func TestAddLinksWithMoreAttributesThanLimit(t *testing.T) { }), parent: sc.WithRemote(true), name: "span0", - links: []trace.Link{ + links: []Link{ { SpanContext: sc1, Attributes: []attribute.KeyValue{k1v1}, diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index 0e6da2e081d..ece4633c525 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -63,7 +63,7 @@ type SpanStub struct { EndTime time.Time Attributes []attribute.KeyValue Events []tracesdk.Event - Links []trace.Link + Links []tracesdk.Link Status tracesdk.Status DroppedAttributes int DroppedEvents int @@ -133,7 +133,7 @@ type spanSnapshot struct { endTime time.Time attributes []attribute.KeyValue events []tracesdk.Event - links []trace.Link + links []tracesdk.Link status tracesdk.Status droppedAttributes int droppedEvents int @@ -150,7 +150,7 @@ func (s spanSnapshot) SpanKind() trace.SpanKind { return s.spanKind } func (s spanSnapshot) StartTime() time.Time { return s.startTime } func (s spanSnapshot) EndTime() time.Time { return s.endTime } func (s spanSnapshot) Attributes() []attribute.KeyValue { return s.attributes } -func (s spanSnapshot) Links() []trace.Link { return s.links } +func (s spanSnapshot) Links() []tracesdk.Link { return s.links } func (s spanSnapshot) Events() []tracesdk.Event { return s.events } func (s spanSnapshot) Status() tracesdk.Status { return s.status } func (s spanSnapshot) DroppedAttributes() int { return s.droppedAttributes } diff --git a/trace/trace.go b/trace/trace.go index 8564cb9dfe6..0923ceb98d5 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -402,10 +402,6 @@ type Link struct { // Attributes describe the aspects of the link. Attributes []attribute.KeyValue - - // DroppedAttributeCount is the number of attributes that were not - // recorded due to configured limits being reached. - DroppedAttributeCount int } // LinkFromContext returns a link encapsulating the SpanContext in the provided ctx. From 7a624ac21cea7661ca6d4eacc5f98e39ee79e3bc Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 26 Jul 2021 08:12:53 -0700 Subject: [PATCH 2/3] Deprecated the oteltest.TraceStateFromKeyValues function (#2122) * Deprecated the oteltest.TraceStateFromKeyValues func * Update changelog * make precommit --- CHANGELOG.md | 2 + exporters/otlp/otlptrace/go.mod | 1 - .../internal/tracetransform/span_test.go | 4 +- exporters/stdout/stdouttrace/go.mod | 1 - exporters/stdout/stdouttrace/trace_test.go | 3 +- oteltest/tracestate.go | 2 + sdk/trace/sampling_test.go | 4 +- sdk/trace/trace_test.go | 61 ++++++++----------- 8 files changed, 34 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdfa4ea2a9a..e5956b5b8a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/exporters/otlp/otlptrace/go.mod b/exporters/otlp/otlptrace/go.mod index 5ffbc3fb39b..1489dc47a77 100644 --- a/exporters/otlp/otlptrace/go.mod +++ b/exporters/otlp/otlptrace/go.mod @@ -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 diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index d220d770ab3..335218dfa6c 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -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}, diff --git a/exporters/stdout/stdouttrace/go.mod b/exporters/stdout/stdouttrace/go.mod index 6e043bdc9ea..a3a483e907d 100644 --- a/exporters/stdout/stdouttrace/go.mod +++ b/exporters/stdout/stdouttrace/go.mod @@ -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 ) diff --git a/exporters/stdout/stdouttrace/trace_test.go b/exporters/stdout/stdouttrace/trace_test.go index e54571b0e73..a8627a61bdb 100644 --- a/exporters/stdout/stdouttrace/trace_test.go +++ b/exporters/stdout/stdouttrace/trace_test.go @@ -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")) diff --git a/oteltest/tracestate.go b/oteltest/tracestate.go index b12743fd35f..4c5d029a311 100644 --- a/oteltest/tracestate.go +++ b/oteltest/tracestate.go @@ -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 diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 6db9cfcfa23..28e3e7736b3 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -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) } diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index e7e2084c883..df463cd1fae 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -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, }, } From bbe6ca40a7128c68544e9a637592dd635b37084a Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 26 Jul 2021 08:40:36 -0700 Subject: [PATCH 3/3] Deprecate oteltest.Harness for removal (#2123) * Deprecate oteltest.Harness for removal * Add changes to changelog * Alias oteltest.Harness to internaltest * Update oteltest/tracer_test.go remove `oteltest` import. Co-authored-by: Anthony Mirabella --- CHANGELOG.md | 1 + internal/internaltest/harness.go | 341 +++++++++++++++++++++++++++++++ oteltest/harness.go | 321 +---------------------------- oteltest/tracer_test.go | 3 +- sdk/go.mod | 1 - sdk/trace/trace_test.go | 3 +- 6 files changed, 352 insertions(+), 318 deletions(-) create mode 100644 internal/internaltest/harness.go diff --git a/CHANGELOG.md b/CHANGELOG.md index e5956b5b8a4..9119f26f9ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ 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 `Harness` type from the `go.opentelemetry.io/otel/oteltest` package and its associated creation function, `NewHarness` are deprecated and will be removed in the next release. (#2123) - The `TraceStateFromKeyValues` function from the `go.opentelemetry.io/otel/oteltest` package is deprecated. Use the `trace.ParseTraceState` function instead. (#2122) diff --git a/internal/internaltest/harness.go b/internal/internaltest/harness.go new file mode 100644 index 00000000000..88306803244 --- /dev/null +++ b/internal/internaltest/harness.go @@ -0,0 +1,341 @@ +// Copyright The OpenTelemetry Authors +// +// 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 internaltest // import "go.opentelemetry.io/otel/internal/internaltest" + +import ( + "context" + "fmt" + "sync" + "testing" + "time" + + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/internal/matchers" + "go.opentelemetry.io/otel/trace" +) + +// Harness is a testing harness used to test implementations of the +// OpenTelemetry API. +type Harness struct { + t *testing.T +} + +// NewHarness returns an instantiated *Harness using t. +func NewHarness(t *testing.T) *Harness { + return &Harness{ + t: t, + } +} + +// TestTracerProvider runs validation tests for an implementation of the OpenTelemetry +// TracerProvider API. +func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider) { + h.t.Run("#Start", func(t *testing.T) { + t.Run("allow creating an arbitrary number of TracerProvider instances", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + + tp1 := subjectFactory() + tp2 := subjectFactory() + + e.Expect(tp1).NotToEqual(tp2) + }) + t.Run("all methods are safe to be called concurrently", func(t *testing.T) { + t.Parallel() + + runner := func(tp trace.TracerProvider) <-chan struct{} { + done := make(chan struct{}) + go func(tp trace.TracerProvider) { + var wg sync.WaitGroup + for i := 0; i < 20; i++ { + wg.Add(1) + go func(name, version string) { + _ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) + wg.Done() + }(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) + } + wg.Wait() + done <- struct{}{} + }(tp) + return done + } + + matchers.NewExpecter(t).Expect(func() { + // Run with multiple TracerProvider to ensure they encapsulate + // their own Tracers. + tp1 := subjectFactory() + tp2 := subjectFactory() + + done1 := runner(tp1) + done2 := runner(tp2) + + <-done1 + <-done2 + }).NotToPanic() + }) + }) +} + +// TestTracer runs validation tests for an implementation of the OpenTelemetry +// Tracer API. +func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { + h.t.Run("#Start", func(t *testing.T) { + t.Run("propagates the original context", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + ctxKey := testCtxKey{} + ctxValue := "ctx value" + ctx := context.WithValue(context.Background(), ctxKey, ctxValue) + + ctx, _ = subject.Start(ctx, "test") + + e.Expect(ctx.Value(ctxKey)).ToEqual(ctxValue) + }) + + t.Run("returns a span containing the expected properties", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + _, span := subject.Start(context.Background(), "test") + + e.Expect(span).NotToBeNil() + + e.Expect(span.SpanContext().IsValid()).ToBeTrue() + }) + + t.Run("stores the span on the provided context", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + ctx, span := subject.Start(context.Background(), "test") + + e.Expect(span).NotToBeNil() + e.Expect(span.SpanContext()).NotToEqual(trace.SpanContext{}) + e.Expect(trace.SpanFromContext(ctx)).ToEqual(span) + }) + + t.Run("starts spans with unique trace and span IDs", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + _, span1 := subject.Start(context.Background(), "span1") + _, span2 := subject.Start(context.Background(), "span2") + + sc1 := span1.SpanContext() + sc2 := span2.SpanContext() + + e.Expect(sc1.TraceID()).NotToEqual(sc2.TraceID()) + e.Expect(sc1.SpanID()).NotToEqual(sc2.SpanID()) + }) + + t.Run("propagates a parent's trace ID through the context", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + ctx, parent := subject.Start(context.Background(), "parent") + _, child := subject.Start(ctx, "child") + + psc := parent.SpanContext() + csc := child.SpanContext() + + e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) + e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) + }) + + t.Run("ignores parent's trace ID when new root is requested", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + ctx, parent := subject.Start(context.Background(), "parent") + _, child := subject.Start(ctx, "child", trace.WithNewRoot()) + + psc := parent.SpanContext() + csc := child.SpanContext() + + e.Expect(csc.TraceID()).NotToEqual(psc.TraceID()) + e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) + }) + + t.Run("propagates remote parent's trace ID through the context", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + _, remoteParent := subject.Start(context.Background(), "remote parent") + parentCtx := trace.ContextWithRemoteSpanContext(context.Background(), remoteParent.SpanContext()) + _, child := subject.Start(parentCtx, "child") + + psc := remoteParent.SpanContext() + csc := child.SpanContext() + + e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) + e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) + }) + + t.Run("ignores remote parent's trace ID when new root is requested", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + subject := subjectFactory() + + _, remoteParent := subject.Start(context.Background(), "remote parent") + parentCtx := trace.ContextWithRemoteSpanContext(context.Background(), remoteParent.SpanContext()) + _, child := subject.Start(parentCtx, "child", trace.WithNewRoot()) + + psc := remoteParent.SpanContext() + csc := child.SpanContext() + + e.Expect(csc.TraceID()).NotToEqual(psc.TraceID()) + e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) + }) + + t.Run("all methods are safe to be called concurrently", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + tracer := subjectFactory() + + ctx, parent := tracer.Start(context.Background(), "span") + + runner := func(tp trace.Tracer) <-chan struct{} { + done := make(chan struct{}) + go func(tp trace.Tracer) { + var wg sync.WaitGroup + for i := 0; i < 20; i++ { + wg.Add(1) + go func(name string) { + defer wg.Done() + _, child := tp.Start(ctx, name) + + psc := parent.SpanContext() + csc := child.SpanContext() + + e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) + e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) + }(fmt.Sprintf("span %d", i)) + } + wg.Wait() + done <- struct{}{} + }(tp) + return done + } + + e.Expect(func() { + done := runner(tracer) + + <-done + }).NotToPanic() + }) + }) + + h.testSpan(subjectFactory) +} + +func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { + var methods = map[string]func(span trace.Span){ + "#End": func(span trace.Span) { + span.End() + }, + "#AddEvent": func(span trace.Span) { + span.AddEvent("test event") + }, + "#AddEventWithTimestamp": func(span trace.Span) { + span.AddEvent("test event", trace.WithTimestamp(time.Now().Add(1*time.Second))) + }, + "#SetStatus": func(span trace.Span) { + span.SetStatus(codes.Error, "internal") + }, + "#SetName": func(span trace.Span) { + span.SetName("new name") + }, + "#SetAttributes": func(span trace.Span) { + span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) + }, + } + var mechanisms = map[string]func() trace.Span{ + "Span created via Tracer#Start": func() trace.Span { + tracer := tracerFactory() + _, subject := tracer.Start(context.Background(), "test") + + return subject + }, + "Span created via span.TracerProvider()": func() trace.Span { + ctx, spanA := tracerFactory().Start(context.Background(), "span1") + + _, spanB := spanA.TracerProvider().Tracer("second").Start(ctx, "span2") + return spanB + }, + } + + for mechanismName, mechanism := range mechanisms { + h.t.Run(mechanismName, func(t *testing.T) { + for methodName, method := range methods { + t.Run(methodName, func(t *testing.T) { + t.Run("is thread-safe", func(t *testing.T) { + t.Parallel() + + span := mechanism() + + wg := &sync.WaitGroup{} + wg.Add(2) + + go func() { + defer wg.Done() + + method(span) + }() + + go func() { + defer wg.Done() + + method(span) + }() + + wg.Wait() + }) + }) + } + + t.Run("#End", func(t *testing.T) { + t.Run("can be called multiple times", func(t *testing.T) { + t.Parallel() + + span := mechanism() + + span.End() + span.End() + }) + }) + }) + } +} + +type testCtxKey struct{} diff --git a/oteltest/harness.go b/oteltest/harness.go index 140d93bb7cb..aed51395ed9 100644 --- a/oteltest/harness.go +++ b/oteltest/harness.go @@ -15,327 +15,20 @@ package oteltest // import "go.opentelemetry.io/otel/oteltest" import ( - "context" - "fmt" - "sync" "testing" - "time" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/internal/matchers" - "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/otel/internal/internaltest" ) // Harness is a testing harness used to test implementations of the // OpenTelemetry API. -type Harness struct { - t *testing.T -} +// +// Deprecated: this will be removed in the next major release. +type Harness = internaltest.Harness // NewHarness returns an instantiated *Harness using t. +// +// Deprecated: this will be removed in the next major release. func NewHarness(t *testing.T) *Harness { - return &Harness{ - t: t, - } -} - -// TestTracerProvider runs validation tests for an implementation of the OpenTelemetry -// TracerProvider API. -func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider) { - h.t.Run("#Start", func(t *testing.T) { - t.Run("allow creating an arbitrary number of TracerProvider instances", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - - tp1 := subjectFactory() - tp2 := subjectFactory() - - e.Expect(tp1).NotToEqual(tp2) - }) - t.Run("all methods are safe to be called concurrently", func(t *testing.T) { - t.Parallel() - - runner := func(tp trace.TracerProvider) <-chan struct{} { - done := make(chan struct{}) - go func(tp trace.TracerProvider) { - var wg sync.WaitGroup - for i := 0; i < 20; i++ { - wg.Add(1) - go func(name, version string) { - _ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) - wg.Done() - }(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) - } - wg.Wait() - done <- struct{}{} - }(tp) - return done - } - - matchers.NewExpecter(t).Expect(func() { - // Run with multiple TracerProvider to ensure they encapsulate - // their own Tracers. - tp1 := subjectFactory() - tp2 := subjectFactory() - - done1 := runner(tp1) - done2 := runner(tp2) - - <-done1 - <-done2 - }).NotToPanic() - }) - }) + return internaltest.NewHarness(t) } - -// TestTracer runs validation tests for an implementation of the OpenTelemetry -// Tracer API. -func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { - h.t.Run("#Start", func(t *testing.T) { - t.Run("propagates the original context", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - ctxKey := testCtxKey{} - ctxValue := "ctx value" - ctx := context.WithValue(context.Background(), ctxKey, ctxValue) - - ctx, _ = subject.Start(ctx, "test") - - e.Expect(ctx.Value(ctxKey)).ToEqual(ctxValue) - }) - - t.Run("returns a span containing the expected properties", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - _, span := subject.Start(context.Background(), "test") - - e.Expect(span).NotToBeNil() - - e.Expect(span.SpanContext().IsValid()).ToBeTrue() - }) - - t.Run("stores the span on the provided context", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - ctx, span := subject.Start(context.Background(), "test") - - e.Expect(span).NotToBeNil() - e.Expect(span.SpanContext()).NotToEqual(trace.SpanContext{}) - e.Expect(trace.SpanFromContext(ctx)).ToEqual(span) - }) - - t.Run("starts spans with unique trace and span IDs", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - _, span1 := subject.Start(context.Background(), "span1") - _, span2 := subject.Start(context.Background(), "span2") - - sc1 := span1.SpanContext() - sc2 := span2.SpanContext() - - e.Expect(sc1.TraceID()).NotToEqual(sc2.TraceID()) - e.Expect(sc1.SpanID()).NotToEqual(sc2.SpanID()) - }) - - t.Run("propagates a parent's trace ID through the context", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - ctx, parent := subject.Start(context.Background(), "parent") - _, child := subject.Start(ctx, "child") - - psc := parent.SpanContext() - csc := child.SpanContext() - - e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) - e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) - }) - - t.Run("ignores parent's trace ID when new root is requested", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - ctx, parent := subject.Start(context.Background(), "parent") - _, child := subject.Start(ctx, "child", trace.WithNewRoot()) - - psc := parent.SpanContext() - csc := child.SpanContext() - - e.Expect(csc.TraceID()).NotToEqual(psc.TraceID()) - e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) - }) - - t.Run("propagates remote parent's trace ID through the context", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - _, remoteParent := subject.Start(context.Background(), "remote parent") - parentCtx := trace.ContextWithRemoteSpanContext(context.Background(), remoteParent.SpanContext()) - _, child := subject.Start(parentCtx, "child") - - psc := remoteParent.SpanContext() - csc := child.SpanContext() - - e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) - e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) - }) - - t.Run("ignores remote parent's trace ID when new root is requested", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - subject := subjectFactory() - - _, remoteParent := subject.Start(context.Background(), "remote parent") - parentCtx := trace.ContextWithRemoteSpanContext(context.Background(), remoteParent.SpanContext()) - _, child := subject.Start(parentCtx, "child", trace.WithNewRoot()) - - psc := remoteParent.SpanContext() - csc := child.SpanContext() - - e.Expect(csc.TraceID()).NotToEqual(psc.TraceID()) - e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) - }) - - t.Run("all methods are safe to be called concurrently", func(t *testing.T) { - t.Parallel() - - e := matchers.NewExpecter(t) - tracer := subjectFactory() - - ctx, parent := tracer.Start(context.Background(), "span") - - runner := func(tp trace.Tracer) <-chan struct{} { - done := make(chan struct{}) - go func(tp trace.Tracer) { - var wg sync.WaitGroup - for i := 0; i < 20; i++ { - wg.Add(1) - go func(name string) { - defer wg.Done() - _, child := tp.Start(ctx, name) - - psc := parent.SpanContext() - csc := child.SpanContext() - - e.Expect(csc.TraceID()).ToEqual(psc.TraceID()) - e.Expect(csc.SpanID()).NotToEqual(psc.SpanID()) - }(fmt.Sprintf("span %d", i)) - } - wg.Wait() - done <- struct{}{} - }(tp) - return done - } - - e.Expect(func() { - done := runner(tracer) - - <-done - }).NotToPanic() - }) - }) - - h.testSpan(subjectFactory) -} - -func (h *Harness) testSpan(tracerFactory func() trace.Tracer) { - var methods = map[string]func(span trace.Span){ - "#End": func(span trace.Span) { - span.End() - }, - "#AddEvent": func(span trace.Span) { - span.AddEvent("test event") - }, - "#AddEventWithTimestamp": func(span trace.Span) { - span.AddEvent("test event", trace.WithTimestamp(time.Now().Add(1*time.Second))) - }, - "#SetStatus": func(span trace.Span) { - span.SetStatus(codes.Error, "internal") - }, - "#SetName": func(span trace.Span) { - span.SetName("new name") - }, - "#SetAttributes": func(span trace.Span) { - span.SetAttributes(attribute.String("key1", "value"), attribute.Int("key2", 123)) - }, - } - var mechanisms = map[string]func() trace.Span{ - "Span created via Tracer#Start": func() trace.Span { - tracer := tracerFactory() - _, subject := tracer.Start(context.Background(), "test") - - return subject - }, - "Span created via span.TracerProvider()": func() trace.Span { - ctx, spanA := tracerFactory().Start(context.Background(), "span1") - - _, spanB := spanA.TracerProvider().Tracer("second").Start(ctx, "span2") - return spanB - }, - } - - for mechanismName, mechanism := range mechanisms { - h.t.Run(mechanismName, func(t *testing.T) { - for methodName, method := range methods { - t.Run(methodName, func(t *testing.T) { - t.Run("is thread-safe", func(t *testing.T) { - t.Parallel() - - span := mechanism() - - wg := &sync.WaitGroup{} - wg.Add(2) - - go func() { - defer wg.Done() - - method(span) - }() - - go func() { - defer wg.Done() - - method(span) - }() - - wg.Wait() - }) - }) - } - - t.Run("#End", func(t *testing.T) { - t.Run("can be called multiple times", func(t *testing.T) { - t.Parallel() - - span := mechanism() - - span.End() - span.End() - }) - }) - }) - } -} - -type testCtxKey struct{} diff --git a/oteltest/tracer_test.go b/oteltest/tracer_test.go index 69de7472363..9da214538fa 100644 --- a/oteltest/tracer_test.go +++ b/oteltest/tracer_test.go @@ -23,6 +23,7 @@ import ( "time" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/internal/internaltest" "go.opentelemetry.io/otel/internal/matchers" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/trace" @@ -31,7 +32,7 @@ import ( func TestTracer(t *testing.T) { tp := oteltest.NewTracerProvider() - oteltest.NewHarness(t).TestTracer(func() func() trace.Tracer { + internaltest.NewHarness(t).TestTracer(func() func() trace.Tracer { tp := oteltest.NewTracerProvider() var i uint64 return func() trace.Tracer { diff --git a/sdk/go.mod b/sdk/go.mod index 6925b631f6b..f4fce1474b0 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -8,7 +8,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/trace v1.0.0-RC1 golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 ) diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index df463cd1fae..01007f2ce05 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -29,7 +29,6 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/oteltest" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "go.opentelemetry.io/otel/trace" @@ -78,7 +77,7 @@ func init() { } func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) { - harness := oteltest.NewHarness(t) + harness := ottest.NewHarness(t) harness.TestTracerProvider(func() trace.TracerProvider { return NewTracerProvider(WithSampler(TraceIDRatioBased(0)))