From c6c155de6f254ac2d41a57b9a85a83b62d1095a3 Mon Sep 17 00:00:00 2001 From: tensorchen Date: Sat, 2 May 2020 20:17:11 +0800 Subject: [PATCH 1/3] Move SpanContext from core package into trace --- api/testharness/harness.go | 3 +- api/trace/always_off_sampler.go | 6 +- api/trace/always_off_sampler_test.go | 2 +- api/trace/always_on_sampler.go | 6 +- api/trace/always_on_sampler_test.go | 2 +- api/trace/api.go | 6 +- api/trace/b3_propagator.go | 61 ++++++++-------- api/trace/context.go | 10 ++- api/trace/context_test.go | 4 +- api/trace/noop_span.go | 4 +- api/trace/sampler.go | 6 +- api/{core => trace}/span_context.go | 2 +- api/{core => trace}/span_context_test.go | 64 ++++++++--------- .../testtrace/b3_propagator_data_test.go | 65 +++++++++-------- api/trace/testtrace/generator.go | 14 ++-- api/trace/testtrace/propagator_test.go | 7 +- api/trace/testtrace/span.go | 14 ++-- ...trace_context_propagator_benchmark_test.go | 9 ++- .../trace_context_propagator_test.go | 53 +++++++------- api/trace/testtrace/tracer.go | 8 +-- api/trace/trace_context_propagator.go | 41 ++++++----- bridge/opentracing/bridge.go | 8 +-- bridge/opentracing/internal/mock.go | 30 ++++---- bridge/opentracing/mix_test.go | 28 ++++---- .../otlp/internal/transform/span_test.go | 22 +++--- exporters/otlp/otlp_span_test.go | 20 +++--- exporters/trace/jaeger/jaeger_test.go | 12 ++-- exporters/trace/stdout/stdout_test.go | 6 +- exporters/trace/zipkin/exporter_test.go | 17 +++-- exporters/trace/zipkin/model.go | 6 +- exporters/trace/zipkin/model_test.go | 72 +++++++++---------- internal/trace/mock_span.go | 6 +- internal/trace/mock_tracer.go | 7 +- internal/trace/parent/parent.go | 8 +-- plugin/grpctrace/grpctrace.go | 2 +- plugin/httptrace/httptrace.go | 2 +- plugin/othttp/transport_test.go | 3 +- sdk/export/trace/trace.go | 4 +- sdk/trace/batch_span_processor_test.go | 11 ++- sdk/trace/benchmark_test.go | 7 +- sdk/trace/id_generator.go | 11 +-- sdk/trace/internal/internal.go | 8 ++- sdk/trace/sampling.go | 6 +- sdk/trace/sampling_test.go | 17 ++--- sdk/trace/simple_span_processor_test.go | 7 +- sdk/trace/span.go | 22 +++--- sdk/trace/trace_test.go | 66 ++++++++--------- 47 files changed, 392 insertions(+), 403 deletions(-) rename api/{core => trace}/span_context.go (99%) rename api/{core => trace}/span_context_test.go (81%) diff --git a/api/testharness/harness.go b/api/testharness/harness.go index b64dfbb87..834d94e45 100644 --- a/api/testharness/harness.go +++ b/api/testharness/harness.go @@ -23,7 +23,6 @@ import ( "google.golang.org/grpc/codes" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/key" "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/internal/matchers" @@ -79,7 +78,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) { ctx, span := subject.Start(context.Background(), "test") e.Expect(span).NotToBeNil() - e.Expect(span.SpanContext()).NotToEqual(core.EmptySpanContext()) + e.Expect(span.SpanContext()).NotToEqual(trace.EmptySpanContext()) e.Expect(trace.SpanFromContext(ctx)).ToEqual(span) }) diff --git a/api/trace/always_off_sampler.go b/api/trace/always_off_sampler.go index 116afaa70..dbc82fea8 100644 --- a/api/trace/always_off_sampler.go +++ b/api/trace/always_off_sampler.go @@ -30,10 +30,10 @@ type alwaysOffSampler struct{} // It always returns a Decision with Sampled value set to false // and with Attributes set to an empty slice. func (ns alwaysOffSampler) ShouldSample( - _ core.SpanContext, + _ SpanContext, _ bool, - _ core.TraceID, - _ core.SpanID, + _ TraceID, + _ SpanID, _ string, _ SpanKind, _ []core.KeyValue, diff --git a/api/trace/always_off_sampler_test.go b/api/trace/always_off_sampler_test.go index 841c667d2..ff0065c70 100644 --- a/api/trace/always_off_sampler_test.go +++ b/api/trace/always_off_sampler_test.go @@ -24,7 +24,7 @@ import ( func TestNeverSamperShouldSample(t *testing.T) { gotD := AlwaysOffSampler().ShouldSample( - core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) + SpanContext{}, false, TraceID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) wantD := Decision{Sampled: false} if diff := cmp.Diff(wantD, gotD); diff != "" { t.Errorf("Decision: +got, -want%v", diff) diff --git a/api/trace/always_on_sampler.go b/api/trace/always_on_sampler.go index ff2c1b330..b92d2b0e4 100644 --- a/api/trace/always_on_sampler.go +++ b/api/trace/always_on_sampler.go @@ -30,10 +30,10 @@ type alwaysOnSampler struct{} // It always returns a Decision with Sampled value set to true // and with Attributes set to an empty slice. func (as alwaysOnSampler) ShouldSample( - _ core.SpanContext, + _ SpanContext, _ bool, - _ core.TraceID, - _ core.SpanID, + _ TraceID, + _ SpanID, _ string, _ SpanKind, _ []core.KeyValue, diff --git a/api/trace/always_on_sampler_test.go b/api/trace/always_on_sampler_test.go index 7030621a4..2cf033560 100644 --- a/api/trace/always_on_sampler_test.go +++ b/api/trace/always_on_sampler_test.go @@ -24,7 +24,7 @@ import ( func TestAlwaysOnSamplerShouldSample(t *testing.T) { gotD := AlwaysOnSampler().ShouldSample( - core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) + SpanContext{}, false, TraceID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) wantD := Decision{Sampled: true} if diff := cmp.Diff(wantD, gotD); diff != "" { t.Errorf("Decision: +got, -want%v", diff) diff --git a/api/trace/api.go b/api/trace/api.go index 859024299..c8414d47c 100644 --- a/api/trace/api.go +++ b/api/trace/api.go @@ -105,7 +105,7 @@ type Span interface { // SpanContext returns span context of the span. Returned SpanContext is usable // even after the span ends. - SpanContext() core.SpanContext + SpanContext() SpanContext // SetStatus sets the status of the span in the form of a code // and a message. SetStatus overrides the value of previous @@ -152,7 +152,7 @@ type StartConfig struct { // on service provider side so two traces (from Client and from Service Provider) can // be correlated. type Link struct { - core.SpanContext + SpanContext Attributes []core.KeyValue } @@ -248,7 +248,7 @@ func WithNewRoot() StartOption { } // LinkedTo allows instantiating a Span with initial Links. -func LinkedTo(sc core.SpanContext, attrs ...core.KeyValue) StartOption { +func LinkedTo(sc SpanContext, attrs ...core.KeyValue) StartOption { return func(c *StartConfig) { c.Links = append(c.Links, Link{sc, attrs}) } diff --git a/api/trace/b3_propagator.go b/api/trace/b3_propagator.go index 9c8d41fa0..679ef9eaa 100644 --- a/api/trace/b3_propagator.go +++ b/api/trace/b3_propagator.go @@ -19,7 +19,6 @@ import ( "fmt" "strings" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/propagation" ) @@ -57,7 +56,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) { return } if b3.SingleHeader { - sampled := sc.TraceFlags & core.TraceFlagsSampled + sampled := sc.TraceFlags & TraceFlagsSampled supplier.Set(B3SingleHeader, fmt.Sprintf("%s-%s-%.1d", sc.TraceID, sc.SpanID, sampled)) } else { @@ -76,7 +75,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) { // Extract retrieves B3 Headers from the supplier func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context { - var sc core.SpanContext + var sc SpanContext if b3.SingleHeader { sc = b3.extractSingleHeader(supplier) } else { @@ -88,84 +87,84 @@ func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) con return ContextWithRemoteSpanContext(ctx, sc) } -func (b3 B3) extract(supplier propagation.HTTPSupplier) core.SpanContext { - tid, err := core.TraceIDFromHex(supplier.Get(B3TraceIDHeader)) +func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext { + tid, err := TraceIDFromHex(supplier.Get(B3TraceIDHeader)) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } - sid, err := core.SpanIDFromHex(supplier.Get(B3SpanIDHeader)) + sid, err := SpanIDFromHex(supplier.Get(B3SpanIDHeader)) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } sampled, ok := b3.extractSampledState(supplier.Get(B3SampledHeader)) if !ok { - return core.EmptySpanContext() + return EmptySpanContext() } debug, ok := b3.extracDebugFlag(supplier.Get(B3DebugFlagHeader)) if !ok { - return core.EmptySpanContext() + return EmptySpanContext() } - if debug == core.TraceFlagsSampled { - sampled = core.TraceFlagsSampled + if debug == TraceFlagsSampled { + sampled = TraceFlagsSampled } - sc := core.SpanContext{ + sc := SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: sampled, } if !sc.IsValid() { - return core.EmptySpanContext() + return EmptySpanContext() } return sc } -func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) core.SpanContext { +func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) SpanContext { h := supplier.Get(B3SingleHeader) if h == "" || h == "0" { - return core.EmptySpanContext() + return EmptySpanContext() } - sc := core.SpanContext{} + sc := SpanContext{} parts := strings.Split(h, "-") l := len(parts) if l > 4 { - return core.EmptySpanContext() + return EmptySpanContext() } if l < 2 { - return core.EmptySpanContext() + return EmptySpanContext() } var err error - sc.TraceID, err = core.TraceIDFromHex(parts[0]) + sc.TraceID, err = TraceIDFromHex(parts[0]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } - sc.SpanID, err = core.SpanIDFromHex(parts[1]) + sc.SpanID, err = SpanIDFromHex(parts[1]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } if l > 2 { var ok bool sc.TraceFlags, ok = b3.extractSampledState(parts[2]) if !ok { - return core.EmptySpanContext() + return EmptySpanContext() } } if l == 4 { - _, err = core.SpanIDFromHex(parts[3]) + _, err = SpanIDFromHex(parts[3]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } } if !sc.IsValid() { - return core.EmptySpanContext() + return EmptySpanContext() } return sc @@ -177,14 +176,14 @@ func (b3 B3) extractSampledState(sampled string) (flag byte, ok bool) { case "", "0": return 0, true case "1": - return core.TraceFlagsSampled, true + return TraceFlagsSampled, true case "true": if !b3.SingleHeader { - return core.TraceFlagsSampled, true + return TraceFlagsSampled, true } case "d": if b3.SingleHeader { - return core.TraceFlagsSampled, true + return TraceFlagsSampled, true } } return 0, false @@ -196,7 +195,7 @@ func (b3 B3) extracDebugFlag(debug string) (flag byte, ok bool) { case "", "0": return 0, true case "1": - return core.TraceFlagsSampled, true + return TraceFlagsSampled, true } return 0, false } diff --git a/api/trace/context.go b/api/trace/context.go index 27ca98fdd..489e3c120 100644 --- a/api/trace/context.go +++ b/api/trace/context.go @@ -16,8 +16,6 @@ package trace import ( "context" - - "go.opentelemetry.io/otel/api/core" ) type traceContextKeyType int @@ -43,15 +41,15 @@ func SpanFromContext(ctx context.Context) Span { // ContextWithRemoteSpanContext creates a new context with a remote // span context set to the passed span context. -func ContextWithRemoteSpanContext(ctx context.Context, sc core.SpanContext) context.Context { +func ContextWithRemoteSpanContext(ctx context.Context, sc SpanContext) context.Context { return context.WithValue(ctx, remoteContextKey, sc) } // RemoteSpanContextFromContext returns the remote span context stored // in the context. -func RemoteSpanContextFromContext(ctx context.Context) core.SpanContext { - if sc, ok := ctx.Value(remoteContextKey).(core.SpanContext); ok { +func RemoteSpanContextFromContext(ctx context.Context) SpanContext { + if sc, ok := ctx.Value(remoteContextKey).(SpanContext); ok { return sc } - return core.EmptySpanContext() + return EmptySpanContext() } diff --git a/api/trace/context_test.go b/api/trace/context_test.go index 48612db48..1c014eebc 100644 --- a/api/trace/context_test.go +++ b/api/trace/context_test.go @@ -72,8 +72,8 @@ type mockSpan struct{} var _ trace.Span = mockSpan{} // SpanContext returns an invalid span context. -func (mockSpan) SpanContext() core.SpanContext { - return core.EmptySpanContext() +func (mockSpan) SpanContext() trace.SpanContext { + return trace.EmptySpanContext() } // IsRecording always returns false for mockSpan. diff --git a/api/trace/noop_span.go b/api/trace/noop_span.go index f06b44dff..5d8a51347 100644 --- a/api/trace/noop_span.go +++ b/api/trace/noop_span.go @@ -29,8 +29,8 @@ type NoopSpan struct { var _ Span = (*NoopSpan)(nil) // SpanContext returns an invalid span context. -func (NoopSpan) SpanContext() core.SpanContext { - return core.EmptySpanContext() +func (NoopSpan) SpanContext() SpanContext { + return EmptySpanContext() } // IsRecording always returns false for NoopSpan. diff --git a/api/trace/sampler.go b/api/trace/sampler.go index aed57cf40..a3709797e 100644 --- a/api/trace/sampler.go +++ b/api/trace/sampler.go @@ -21,10 +21,10 @@ type Sampler interface { // or not sample the span to be created. Decision is based on a Sampler specific // algorithm that takes into account one or more input parameters. ShouldSample( - sc core.SpanContext, + sc SpanContext, remote bool, - traceID core.TraceID, - spanID core.SpanID, + traceID TraceID, + spanID SpanID, spanName string, spanKind SpanKind, attributes []core.KeyValue, diff --git a/api/core/span_context.go b/api/trace/span_context.go similarity index 99% rename from api/core/span_context.go rename to api/trace/span_context.go index b97b600ed..969dbdf38 100644 --- a/api/core/span_context.go +++ b/api/trace/span_context.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package core +package trace import ( "bytes" diff --git a/api/core/span_context_test.go b/api/trace/span_context_test.go similarity index 81% rename from api/core/span_context_test.go rename to api/trace/span_context_test.go index a4e7f9212..16b07fcdf 100644 --- a/api/core/span_context_test.go +++ b/api/trace/span_context_test.go @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package core_test +package trace_test import ( "testing" - "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/api/trace" ) func TestIsValid(t *testing.T) { for _, testcase := range []struct { name string - tid core.TraceID - sid core.SpanID + tid trace.TraceID + sid trace.SpanID want bool }{ { @@ -34,23 +34,23 @@ func TestIsValid(t *testing.T) { want: true, }, { name: "SpanContext.IsValid() returns false if sc has neither an Trace ID nor Span ID", - tid: core.TraceID([16]byte{}), + tid: trace.TraceID([16]byte{}), sid: [8]byte{}, want: false, }, { name: "SpanContext.IsValid() returns false if sc has a Span ID but not a Trace ID", - tid: core.TraceID([16]byte{}), + tid: trace.TraceID([16]byte{}), sid: [8]byte{42}, want: false, }, { name: "SpanContext.IsValid() returns false if sc has a Trace ID but not a Span ID", - tid: core.TraceID([16]byte{1}), + tid: trace.TraceID([16]byte{1}), sid: [8]byte{}, want: false, }, } { t.Run(testcase.name, func(t *testing.T) { - sc := core.SpanContext{ + sc := trace.SpanContext{ TraceID: testcase.tid, SpanID: testcase.sid, } @@ -66,12 +66,12 @@ func TestIsValidFromHex(t *testing.T) { for _, testcase := range []struct { name string hex string - tid core.TraceID + tid trace.TraceID valid bool }{ { name: "Valid TraceID", - tid: core.TraceID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}), + tid: trace.TraceID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}), hex: "80f198ee56343ba864fe8b2a57d3eff7", valid: true, }, { @@ -89,7 +89,7 @@ func TestIsValidFromHex(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - tid, err := core.TraceIDFromHex(testcase.hex) + tid, err := trace.TraceIDFromHex(testcase.hex) if testcase.valid && err != nil { t.Errorf("Expected TraceID %s to be valid but end with error %s", testcase.hex, err.Error()) @@ -109,22 +109,22 @@ func TestIsValidFromHex(t *testing.T) { func TestHasTraceID(t *testing.T) { for _, testcase := range []struct { name string - tid core.TraceID + tid trace.TraceID want bool }{ { name: "SpanContext.HasTraceID() returns true if both Low and High are nonzero", - tid: core.TraceID([16]byte{1}), + tid: trace.TraceID([16]byte{1}), want: true, }, { name: "SpanContext.HasTraceID() returns false if neither Low nor High are nonzero", - tid: core.TraceID{}, + tid: trace.TraceID{}, want: false, }, } { t.Run(testcase.name, func(t *testing.T) { //proto: func (sc SpanContext) HasTraceID() bool{} - sc := core.SpanContext{TraceID: testcase.tid} + sc := trace.SpanContext{TraceID: testcase.tid} have := sc.HasTraceID() if have != testcase.want { t.Errorf("Want: %v, but have: %v", testcase.want, have) @@ -136,16 +136,16 @@ func TestHasTraceID(t *testing.T) { func TestHasSpanID(t *testing.T) { for _, testcase := range []struct { name string - sc core.SpanContext + sc trace.SpanContext want bool }{ { name: "SpanContext.HasSpanID() returns true if self.SpanID != 0", - sc: core.SpanContext{SpanID: [8]byte{42}}, + sc: trace.SpanContext{SpanID: [8]byte{42}}, want: true, }, { name: "SpanContext.HasSpanID() returns false if self.SpanID == 0", - sc: core.SpanContext{}, + sc: trace.SpanContext{}, want: false, }, } { @@ -162,26 +162,26 @@ func TestHasSpanID(t *testing.T) { func TestSpanContextIsSampled(t *testing.T) { for _, testcase := range []struct { name string - sc core.SpanContext + sc trace.SpanContext want bool }{ { name: "sampled", - sc: core.SpanContext{ - TraceID: core.TraceID([16]byte{1}), - TraceFlags: core.TraceFlagsSampled, + sc: trace.SpanContext{ + TraceID: trace.TraceID([16]byte{1}), + TraceFlags: trace.TraceFlagsSampled, }, want: true, }, { name: "sampled plus unused", - sc: core.SpanContext{ - TraceID: core.TraceID([16]byte{1}), - TraceFlags: core.TraceFlagsSampled | core.TraceFlagsUnused, + sc: trace.SpanContext{ + TraceID: trace.TraceID([16]byte{1}), + TraceFlags: trace.TraceFlagsSampled | trace.TraceFlagsUnused, }, want: true, }, { name: "not sampled/default", - sc: core.SpanContext{TraceID: core.TraceID{}}, + sc: trace.SpanContext{TraceID: trace.TraceID{}}, want: false, }, } { @@ -197,17 +197,17 @@ func TestSpanContextIsSampled(t *testing.T) { func TestStringTraceID(t *testing.T) { for _, testcase := range []struct { name string - tid core.TraceID + tid trace.TraceID want string }{ { name: "TraceID.String returns string representation of self.TraceID values > 0", - tid: core.TraceID([16]byte{255}), + tid: trace.TraceID([16]byte{255}), want: "ff000000000000000000000000000000", }, { name: "TraceID.String returns string representation of self.TraceID values == 0", - tid: core.TraceID([16]byte{}), + tid: trace.TraceID([16]byte{}), want: "00000000000000000000000000000000", }, } { @@ -224,17 +224,17 @@ func TestStringTraceID(t *testing.T) { func TestStringSpanID(t *testing.T) { for _, testcase := range []struct { name string - sid core.SpanID + sid trace.SpanID want string }{ { name: "SpanID.String returns string representation of self.SpanID values > 0", - sid: core.SpanID([8]byte{255}), + sid: trace.SpanID([8]byte{255}), want: "ff00000000000000", }, { name: "SpanID.String returns string representation of self.SpanID values == 0", - sid: core.SpanID([8]byte{}), + sid: trace.SpanID([8]byte{}), want: "0000000000000000", }, } { diff --git a/api/trace/testtrace/b3_propagator_data_test.go b/api/trace/testtrace/b3_propagator_data_test.go index d4184b99e..c7a1abc41 100644 --- a/api/trace/testtrace/b3_propagator_data_test.go +++ b/api/trace/testtrace/b3_propagator_data_test.go @@ -15,14 +15,13 @@ package testtrace_test import ( - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace" ) type extractTest struct { name string headers map[string]string - wantSc core.SpanContext + wantSc trace.SpanContext } var extractMultipleHeaders = []extractTest{ @@ -32,7 +31,7 @@ var extractMultipleHeaders = []extractTest{ trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", trace.B3SpanIDHeader: "00f067aa0ba902b7", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -44,7 +43,7 @@ var extractMultipleHeaders = []extractTest{ trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SampledHeader: "0", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -56,10 +55,10 @@ var extractMultipleHeaders = []extractTest{ trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SampledHeader: "1", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -69,10 +68,10 @@ var extractMultipleHeaders = []extractTest{ trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SampledHeader: "true", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -82,10 +81,10 @@ var extractMultipleHeaders = []extractTest{ trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3DebugFlagHeader: "1", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -99,10 +98,10 @@ var extractMultipleHeaders = []extractTest{ trace.B3SampledHeader: "0", trace.B3DebugFlagHeader: "1", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -113,10 +112,10 @@ var extractMultipleHeaders = []extractTest{ trace.B3SampledHeader: "1", trace.B3ParentSpanIDHeader: "00f067aa0ba90200", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -124,7 +123,7 @@ var extractMultipleHeaders = []extractTest{ headers: map[string]string{ trace.B3SampledHeader: "0", }, - wantSc: core.EmptySpanContext(), + wantSc: trace.EmptySpanContext(), }, } @@ -134,7 +133,7 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -144,7 +143,7 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -154,10 +153,10 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -165,10 +164,10 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -176,10 +175,10 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd", }, - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { @@ -187,7 +186,7 @@ var extractSingleHeader = []extractTest{ headers: map[string]string{ trace.B3SingleHeader: "0", }, - wantSc: core.EmptySpanContext(), + wantSc: trace.EmptySpanContext(), }, } @@ -436,7 +435,7 @@ var extractInvalidB3SingleHeader = []extractTest{ type injectTest struct { name string - parentSc core.SpanContext + parentSc trace.SpanContext wantHeaders map[string]string doNotWantHeaders []string } @@ -444,10 +443,10 @@ type injectTest struct { var injectB3MultipleHeader = []injectTest{ { name: "valid spancontext, sampled", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, wantHeaders: map[string]string{ trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", @@ -460,7 +459,7 @@ var injectB3MultipleHeader = []injectTest{ }, { name: "valid spancontext, not sampled", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -475,7 +474,7 @@ var injectB3MultipleHeader = []injectTest{ }, { name: "valid spancontext, with unsupported bit set in traceflags", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, TraceFlags: 0xff, @@ -494,10 +493,10 @@ var injectB3MultipleHeader = []injectTest{ var injectB3SingleleHeader = []injectTest{ { name: "valid spancontext, sampled", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, wantHeaders: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1", @@ -511,7 +510,7 @@ var injectB3SingleleHeader = []injectTest{ }, { name: "valid spancontext, not sampled", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -527,7 +526,7 @@ var injectB3SingleleHeader = []injectTest{ }, { name: "valid spancontext, with unsupported bit set in traceflags", - parentSc: core.SpanContext{ + parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, TraceFlags: 0xff, diff --git a/api/trace/testtrace/generator.go b/api/trace/testtrace/generator.go index f49e547a7..5edf85fee 100644 --- a/api/trace/testtrace/generator.go +++ b/api/trace/testtrace/generator.go @@ -18,12 +18,12 @@ import ( "encoding/binary" "sync" - "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/api/trace" ) type Generator interface { - TraceID() core.TraceID - SpanID() core.SpanID + TraceID() trace.TraceID + SpanID() trace.SpanID } var _ Generator = (*CountGenerator)(nil) @@ -41,7 +41,7 @@ func NewCountGenerator() *CountGenerator { return &CountGenerator{} } -func (g *CountGenerator) TraceID() core.TraceID { +func (g *CountGenerator) TraceID() trace.TraceID { g.lock.Lock() defer g.lock.Unlock() @@ -51,7 +51,7 @@ func (g *CountGenerator) TraceID() core.TraceID { g.traceIDLow++ } - var traceID core.TraceID + var traceID trace.TraceID binary.BigEndian.PutUint64(traceID[0:8], g.traceIDLow) binary.BigEndian.PutUint64(traceID[8:], g.traceIDHigh) @@ -59,13 +59,13 @@ func (g *CountGenerator) TraceID() core.TraceID { return traceID } -func (g *CountGenerator) SpanID() core.SpanID { +func (g *CountGenerator) SpanID() trace.SpanID { g.lock.Lock() defer g.lock.Unlock() g.spanID++ - var spanID core.SpanID + var spanID trace.SpanID binary.BigEndian.PutUint64(spanID[:], g.spanID) diff --git a/api/trace/testtrace/propagator_test.go b/api/trace/testtrace/propagator_test.go index 4768db4e2..0f995188c 100644 --- a/api/trace/testtrace/propagator_test.go +++ b/api/trace/testtrace/propagator_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/trace" ) @@ -33,11 +32,11 @@ type outOfThinAirPropagator struct { var _ propagation.HTTPPropagator = outOfThinAirPropagator{} func (p outOfThinAirPropagator) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context { - traceID, err := core.TraceIDFromHex("938753245abe987f098c0987a9873987") + traceID, err := trace.TraceIDFromHex("938753245abe987f098c0987a9873987") require.NoError(p.t, err) - spanID, err := core.SpanIDFromHex("2345f98c0987a09d") + spanID, err := trace.SpanIDFromHex("2345f98c0987a09d") require.NoError(p.t, err) - sc := core.SpanContext{ + sc := trace.SpanContext{ TraceID: traceID, SpanID: spanID, TraceFlags: 0, diff --git a/api/trace/testtrace/span.go b/api/trace/testtrace/span.go index b3f76644e..a97805aed 100644 --- a/api/trace/testtrace/span.go +++ b/api/trace/testtrace/span.go @@ -39,8 +39,8 @@ var _ trace.Span = (*Span)(nil) type Span struct { lock *sync.RWMutex tracer *Tracer - spanContext core.SpanContext - parentSpanID core.SpanID + spanContext trace.SpanContext + parentSpanID trace.SpanID ended bool name string startTime time.Time @@ -49,7 +49,7 @@ type Span struct { statusMessage string attributes map[core.Key]core.Value events []Event - links map[core.SpanContext][]core.KeyValue + links map[trace.SpanContext][]core.KeyValue } func (s *Span) Tracer() trace.Tracer { @@ -138,7 +138,7 @@ func (s *Span) IsRecording() bool { return true } -func (s *Span) SpanContext() core.SpanContext { +func (s *Span) SpanContext() trace.SpanContext { return s.spanContext } @@ -191,7 +191,7 @@ func (s *Span) Name() string { // ParentSpanID returns the SpanID of the parent Span. // If the Span is a root Span and therefore does not have a parent, the returned SpanID will be invalid // (i.e., it will contain all zeroes). -func (s *Span) ParentSpanID() core.SpanID { +func (s *Span) ParentSpanID() trace.SpanID { return s.parentSpanID } @@ -219,8 +219,8 @@ func (s *Span) Events() []Event { // Links returns the links set on the Span at creation time. // If multiple links for the same SpanContext were set, the last link will be used. -func (s *Span) Links() map[core.SpanContext][]core.KeyValue { - links := make(map[core.SpanContext][]core.KeyValue) +func (s *Span) Links() map[trace.SpanContext][]core.KeyValue { + links := make(map[trace.SpanContext][]core.KeyValue) for sc, attributes := range s.links { links[sc] = append([]core.KeyValue{}, attributes...) diff --git a/api/trace/testtrace/trace_context_propagator_benchmark_test.go b/api/trace/testtrace/trace_context_propagator_benchmark_test.go index b5ad2d75f..54e05fd9a 100644 --- a/api/trace/testtrace/trace_context_propagator_benchmark_test.go +++ b/api/trace/testtrace/trace_context_propagator_benchmark_test.go @@ -19,7 +19,6 @@ import ( "net/http" "testing" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace" mocktrace "go.opentelemetry.io/otel/internal/trace" ) @@ -39,18 +38,18 @@ func BenchmarkInject(b *testing.B) { func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) { b.Run("SampledSpanContext", func(b *testing.B) { var id uint64 - spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") - traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") + traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") mockTracer := &mocktrace.MockTracer{ Sampled: false, StartSpanID: &id, } b.ReportAllocs() - sc := core.SpanContext{ + sc := trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, } ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc) ctx, _ = mockTracer.Start(ctx, "inject") diff --git a/api/trace/testtrace/trace_context_propagator_test.go b/api/trace/testtrace/trace_context_propagator_test.go index 2487dcaec..83ea7d6b6 100644 --- a/api/trace/testtrace/trace_context_propagator_test.go +++ b/api/trace/testtrace/trace_context_propagator_test.go @@ -21,7 +21,6 @@ import ( "github.com/google/go-cmp/cmp" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/trace" mocktrace "go.opentelemetry.io/otel/internal/trace" @@ -32,13 +31,13 @@ var ( spanID = mustSpanIDFromHex("00f067aa0ba902b7") ) -func mustTraceIDFromHex(s string) (t core.TraceID) { - t, _ = core.TraceIDFromHex(s) +func mustTraceIDFromHex(s string) (t trace.TraceID) { + t, _ = trace.TraceIDFromHex(s) return } -func mustSpanIDFromHex(s string) (t core.SpanID) { - t, _ = core.SpanIDFromHex(s) +func mustSpanIDFromHex(s string) (t trace.SpanID) { + t, _ = trace.SpanIDFromHex(s) return } @@ -47,12 +46,12 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { tests := []struct { name string header string - wantSc core.SpanContext + wantSc trace.SpanContext }{ { name: "valid w3cHeader", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -60,34 +59,34 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { { name: "valid w3cHeader and sampled", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { name: "future version", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { name: "future options with sampled bit set", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { name: "future options with sampled bit cleared", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-08", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -95,28 +94,28 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { { name: "future additional data", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-XYZxsf09", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { name: "valid b3Header ending in dash", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, { name: "future valid b3Header ending in dash", header: "01-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-", - wantSc: core.SpanContext{ + wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, }, } @@ -137,7 +136,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { } func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) { - wantSc := core.EmptySpanContext() + wantSc := trace.EmptySpanContext() props := propagation.New(propagation.WithExtractors(trace.TraceContext{})) tests := []struct { name string @@ -233,21 +232,21 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { props := propagation.New(propagation.WithInjectors(trace.TraceContext{})) tests := []struct { name string - sc core.SpanContext + sc trace.SpanContext wantHeader string }{ { name: "valid spancontext, sampled", - sc: core.SpanContext{ + sc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, }, wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01", }, { name: "valid spancontext, not sampled", - sc: core.SpanContext{ + sc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -255,7 +254,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { }, { name: "valid spancontext, with unsupported bit set in traceflags", - sc: core.SpanContext{ + sc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, TraceFlags: 0xff, @@ -264,7 +263,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { }, { name: "invalid spancontext", - sc: core.EmptySpanContext(), + sc: trace.EmptySpanContext(), wantHeader: "", }, } diff --git a/api/trace/testtrace/tracer.go b/api/trace/testtrace/tracer.go index 7dc00f16e..eb6b78950 100644 --- a/api/trace/testtrace/tracer.go +++ b/api/trace/testtrace/tracer.go @@ -51,8 +51,8 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti opt(&c) } - var traceID core.TraceID - var parentSpanID core.SpanID + var traceID trace.TraceID + var parentSpanID trace.SpanID parentSpanContext, _, links := parent.GetSpanContextAndLinks(ctx, c.NewRoot) @@ -75,13 +75,13 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti lock: &sync.RWMutex{}, tracer: t, startTime: startTime, - spanContext: core.SpanContext{ + spanContext: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, parentSpanID: parentSpanID, attributes: make(map[core.Key]core.Value), - links: make(map[core.SpanContext][]core.KeyValue), + links: make(map[trace.SpanContext][]core.KeyValue), } span.SetName(name) diff --git a/api/trace/trace_context_propagator.go b/api/trace/trace_context_propagator.go index ab54ffbf0..685107da3 100644 --- a/api/trace/trace_context_propagator.go +++ b/api/trace/trace_context_propagator.go @@ -21,7 +21,6 @@ import ( "regexp" "strings" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/propagation" ) @@ -52,7 +51,7 @@ func (TraceContext) Inject(ctx context.Context, supplier propagation.HTTPSupplie supportedVersion, sc.TraceID, sc.SpanID, - sc.TraceFlags&core.TraceFlagsSampled) + sc.TraceFlags&TraceFlagsSampled) supplier.Set(traceparentHeader, h) } @@ -64,68 +63,68 @@ func (tc TraceContext) Extract(ctx context.Context, supplier propagation.HTTPSup return ContextWithRemoteSpanContext(ctx, sc) } -func (TraceContext) extract(supplier propagation.HTTPSupplier) core.SpanContext { +func (TraceContext) extract(supplier propagation.HTTPSupplier) SpanContext { h := supplier.Get(traceparentHeader) if h == "" { - return core.EmptySpanContext() + return EmptySpanContext() } h = strings.Trim(h, "-") if !traceCtxRegExp.MatchString(h) { - return core.EmptySpanContext() + return EmptySpanContext() } sections := strings.Split(h, "-") if len(sections) < 4 { - return core.EmptySpanContext() + return EmptySpanContext() } if len(sections[0]) != 2 { - return core.EmptySpanContext() + return EmptySpanContext() } ver, err := hex.DecodeString(sections[0]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } version := int(ver[0]) if version > maxVersion { - return core.EmptySpanContext() + return EmptySpanContext() } if version == 0 && len(sections) != 4 { - return core.EmptySpanContext() + return EmptySpanContext() } if len(sections[1]) != 32 { - return core.EmptySpanContext() + return EmptySpanContext() } - var sc core.SpanContext + var sc SpanContext - sc.TraceID, err = core.TraceIDFromHex(sections[1][:32]) + sc.TraceID, err = TraceIDFromHex(sections[1][:32]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } if len(sections[2]) != 16 { - return core.EmptySpanContext() + return EmptySpanContext() } - sc.SpanID, err = core.SpanIDFromHex(sections[2]) + sc.SpanID, err = SpanIDFromHex(sections[2]) if err != nil { - return core.EmptySpanContext() + return EmptySpanContext() } if len(sections[3]) != 2 { - return core.EmptySpanContext() + return EmptySpanContext() } opts, err := hex.DecodeString(sections[3]) if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) { - return core.EmptySpanContext() + return EmptySpanContext() } - sc.TraceFlags = opts[0] &^ core.TraceFlagsUnused + sc.TraceFlags = opts[0] &^ TraceFlagsUnused if !sc.IsValid() { - return core.EmptySpanContext() + return EmptySpanContext() } return sc diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 631cb8cf1..848d88f62 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -40,12 +40,12 @@ import ( type bridgeSpanContext struct { baggageItems otelcorrelation.Map - otelSpanContext otelcore.SpanContext + otelSpanContext oteltrace.SpanContext } var _ ot.SpanContext = &bridgeSpanContext{} -func newBridgeSpanContext(otelSpanContext otelcore.SpanContext, parentOtSpanContext ot.SpanContext) *bridgeSpanContext { +func newBridgeSpanContext(otelSpanContext oteltrace.SpanContext, parentOtSpanContext ot.SpanContext) *bridgeSpanContext { bCtx := &bridgeSpanContext{ baggageItems: otelcorrelation.NewEmptyMap(), otelSpanContext: otelSpanContext, @@ -582,10 +582,10 @@ func otSpanReferenceTypeToString(refType ot.SpanReferenceType) string { type fakeSpan struct { oteltrace.NoopSpan - sc otelcore.SpanContext + sc oteltrace.SpanContext } -func (s fakeSpan) SpanContext() otelcore.SpanContext { +func (s fakeSpan) SpanContext() oteltrace.SpanContext { return s.sc } diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 5f2823cc2..e3e30edc5 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -49,8 +49,8 @@ type MockContextKeyValue struct { type MockTracer struct { Resources otelcorrelation.Map FinishedSpans []*MockSpan - SpareTraceIDs []otelcore.TraceID - SpareSpanIDs []otelcore.SpanID + SpareTraceIDs []oteltrace.TraceID + SpareSpanIDs []oteltrace.SpanID SpareContextKeyValues []MockContextKeyValue randLock sync.Mutex @@ -87,7 +87,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S if startTime.IsZero() { startTime = time.Now() } - spanContext := otelcore.SpanContext{ + spanContext := oteltrace.SpanContext{ TraceID: t.getTraceID(ctx, &spanOpts), SpanID: t.getSpanID(), TraceFlags: 0, @@ -126,7 +126,7 @@ func (t *MockTracer) addSpareContextValue(ctx context.Context) context.Context { return ctx } -func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.TraceID { +func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.TraceID { if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() { return parent.TraceID } @@ -141,19 +141,19 @@ func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartCo return t.getRandTraceID() } -func (t *MockTracer) getParentSpanID(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.SpanID { +func (t *MockTracer) getParentSpanID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.SpanID { if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() { return parent.SpanID } - return otelcore.SpanID{} + return oteltrace.SpanID{} } -func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.SpanContext { +func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.SpanContext { spanCtx, _, _ := otelparent.GetSpanContextAndLinks(ctx, spanOpts.NewRoot) return spanCtx } -func (t *MockTracer) getSpanID() otelcore.SpanID { +func (t *MockTracer) getSpanID() oteltrace.SpanID { if len(t.SpareSpanIDs) > 0 { spanID := t.SpareSpanIDs[0] t.SpareSpanIDs = t.SpareSpanIDs[1:] @@ -165,21 +165,21 @@ func (t *MockTracer) getSpanID() otelcore.SpanID { return t.getRandSpanID() } -func (t *MockTracer) getRandSpanID() otelcore.SpanID { +func (t *MockTracer) getRandSpanID() oteltrace.SpanID { t.randLock.Lock() defer t.randLock.Unlock() - sid := otelcore.SpanID{} + sid := oteltrace.SpanID{} t.rand.Read(sid[:]) return sid } -func (t *MockTracer) getRandTraceID() otelcore.TraceID { +func (t *MockTracer) getRandTraceID() oteltrace.TraceID { t.randLock.Lock() defer t.randLock.Unlock() - tid := otelcore.TraceID{} + tid := oteltrace.TraceID{} t.rand.Read(tid[:]) return tid @@ -199,21 +199,21 @@ type MockEvent struct { type MockSpan struct { mockTracer *MockTracer officialTracer oteltrace.Tracer - spanContext otelcore.SpanContext + spanContext oteltrace.SpanContext SpanKind oteltrace.SpanKind recording bool Attributes otelcorrelation.Map StartTime time.Time EndTime time.Time - ParentSpanID otelcore.SpanID + ParentSpanID oteltrace.SpanID Events []MockEvent } var _ oteltrace.Span = &MockSpan{} var _ migration.OverrideTracerSpanExtension = &MockSpan{} -func (s *MockSpan) SpanContext() otelcore.SpanContext { +func (s *MockSpan) SpanContext() oteltrace.SpanContext { return s.spanContext } diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index 013b57e41..fd9bf4f8d 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -143,8 +143,8 @@ func TestMixedAPIs(t *testing.T) { // simple test type simpleTest struct { - traceID otelcore.TraceID - spanIDs []otelcore.SpanID + traceID oteltrace.TraceID + spanIDs []oteltrace.SpanID } func newSimpleTest() *simpleTest { @@ -178,11 +178,11 @@ func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context { // current/active span test type currentActiveSpanTest struct { - traceID otelcore.TraceID - spanIDs []otelcore.SpanID + traceID oteltrace.TraceID + spanIDs []oteltrace.SpanID - recordedCurrentOtelSpanIDs []otelcore.SpanID - recordedActiveOTSpanIDs []otelcore.SpanID + recordedCurrentOtelSpanIDs []oteltrace.SpanID + recordedActiveOTSpanIDs []oteltrace.SpanID } func newCurrentActiveSpanTest() *currentActiveSpanTest { @@ -233,7 +233,7 @@ func (cast *currentActiveSpanTest) recordSpans(t *testing.T, ctx context.Context spanID := oteltrace.SpanFromContext(ctx).SpanContext().SpanID cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID) - spanID = otelcore.SpanID{} + spanID = oteltrace.SpanID{} if bridgeSpan, ok := ot.SpanFromContext(ctx).(*bridgeSpan); ok { spanID = bridgeSpan.otelSpan.SpanContext().SpanID } @@ -614,20 +614,20 @@ func generateBaggageKeys(key string) (otKey, otelKey string) { // helpers -func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID otelcore.TraceID, expectedSpanIDs []otelcore.SpanID) { +func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID oteltrace.TraceID, expectedSpanIDs []oteltrace.SpanID) { expectedSpanCount := len(expectedSpanIDs) // reverse spanIDs, since first span ID belongs to root, that // finishes last - spanIDs := make([]otelcore.SpanID, len(expectedSpanIDs)) + spanIDs := make([]oteltrace.SpanID, len(expectedSpanIDs)) copy(spanIDs, expectedSpanIDs) reverse(len(spanIDs), func(i, j int) { spanIDs[i], spanIDs[j] = spanIDs[j], spanIDs[i] }) // the last finished span has no parent - parentSpanIDs := append(spanIDs[1:], otelcore.SpanID{}) + parentSpanIDs := append(spanIDs[1:], oteltrace.SpanID{}) - sks := map[otelcore.SpanID]oteltrace.SpanKind{ + sks := map[oteltrace.SpanID]oteltrace.SpanKind{ {125}: oteltrace.SpanKindProducer, {124}: oteltrace.SpanKindInternal, {123}: oteltrace.SpanKindClient, @@ -661,12 +661,12 @@ func reverse(length int, swap func(i, j int)) { } } -func simpleTraceID() otelcore.TraceID { +func simpleTraceID() oteltrace.TraceID { return [16]byte{123, 42} } -func simpleSpanIDs(count int) []otelcore.SpanID { - base := []otelcore.SpanID{ +func simpleSpanIDs(count int) []oteltrace.SpanID { + base := []oteltrace.SpanID{ {123}, {124}, {125}, diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go index 938d384a1..16a0cee20 100644 --- a/exporters/otlp/internal/transform/span_test.go +++ b/exporters/otlp/internal/transform/span_test.go @@ -123,7 +123,7 @@ func TestLinks(t *testing.T) { l := []apitrace.Link{ {}, { - SpanContext: core.EmptySpanContext(), + SpanContext: apitrace.EmptySpanContext(), Attributes: attrs, }, } @@ -270,12 +270,12 @@ func TestSpanData(t *testing.T) { startTime := time.Unix(1585674086, 1234) endTime := startTime.Add(10 * time.Second) spanData := &export.SpanData{ - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: apitrace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, SpanKind: apitrace.SpanKindServer, - ParentSpanID: core.SpanID{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8}, + ParentSpanID: apitrace.SpanID{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8}, Name: "span data to span data", StartTime: startTime, EndTime: endTime, @@ -293,9 +293,9 @@ func TestSpanData(t *testing.T) { }, Links: []apitrace.Link{ { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, - SpanID: core.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, + SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, TraceFlags: 0, }, Attributes: []core.KeyValue{ @@ -303,9 +303,9 @@ func TestSpanData(t *testing.T) { }, }, { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, - SpanID: core.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, + SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, TraceFlags: 0, }, Attributes: []core.KeyValue{ diff --git a/exporters/otlp/otlp_span_test.go b/exporters/otlp/otlp_span_test.go index 97dba1f7a..32511997c 100644 --- a/exporters/otlp/otlp_span_test.go +++ b/exporters/otlp/otlp_span_test.go @@ -81,9 +81,9 @@ func TestExportSpans(t *testing.T) { { []*tracesdk.SpanData{ { - SpanContext: core.SpanContext{ - TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), - SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), + SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), TraceFlags: byte(1), }, SpanKind: apitrace.SpanKindServer, @@ -99,12 +99,12 @@ func TestExportSpans(t *testing.T) { Resource: resource.New(key.String("instance", "tester-a")), }, { - SpanContext: core.SpanContext{ - TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), - SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2}), + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), + SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2}), TraceFlags: byte(1), }, - ParentSpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), + ParentSpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), SpanKind: apitrace.SpanKindInternal, Name: "internal process", StartTime: startTime, @@ -118,9 +118,9 @@ func TestExportSpans(t *testing.T) { Resource: resource.New(key.String("instance", "tester-a")), }, { - SpanContext: core.SpanContext{ - TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), - SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), + SpanContext: apitrace.SpanContext{ + TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), + SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), TraceFlags: byte(1), }, SpanKind: apitrace.SpanKindServer, diff --git a/exporters/trace/jaeger/jaeger_test.go b/exporters/trace/jaeger/jaeger_test.go index e623c76b3..64a6bafae 100644 --- a/exporters/trace/jaeger/jaeger_test.go +++ b/exporters/trace/jaeger/jaeger_test.go @@ -191,11 +191,11 @@ func TestNewRawExporterWithAgentShouldFailIfEndpointInvalid(t *testing.T) { func Test_spanDataToThrift(t *testing.T) { now := time.Now() - traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") - spanID, _ := core.SpanIDFromHex("0102030405060708") + traceID, _ := apitrace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") + spanID, _ := apitrace.SpanIDFromHex("0102030405060708") - linkTraceID, _ := core.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11") - linkSpanID, _ := core.SpanIDFromHex("0102030405060709") + linkTraceID, _ := apitrace.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11") + linkSpanID, _ := apitrace.SpanIDFromHex("0102030405060709") eventNameValue := "event-test" keyValue := "value" @@ -215,7 +215,7 @@ func Test_spanDataToThrift(t *testing.T) { { name: "no parent", data: &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -224,7 +224,7 @@ func Test_spanDataToThrift(t *testing.T) { EndTime: now, Links: []apitrace.Link{ { - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: linkTraceID, SpanID: linkSpanID, }, diff --git a/exporters/trace/stdout/stdout_test.go b/exporters/trace/stdout/stdout_test.go index 714b28fa3..35b17faac 100644 --- a/exporters/trace/stdout/stdout_test.go +++ b/exporters/trace/stdout/stdout_test.go @@ -40,14 +40,14 @@ func TestExporter_ExportSpan(t *testing.T) { // setup test span now := time.Now() - traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") - spanID, _ := core.SpanIDFromHex("0102030405060708") + traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") + spanID, _ := trace.SpanIDFromHex("0102030405060708") keyValue := "value" doubleValue := 123.456 resource := resource.New(key.String("rk1", "rv11")) testSpan := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: trace.SpanContext{ TraceID: traceID, SpanID: spanID, }, diff --git a/exporters/trace/zipkin/exporter_test.go b/exporters/trace/zipkin/exporter_test.go index 848f38867..bbb0f220b 100644 --- a/exporters/trace/zipkin/exporter_test.go +++ b/exporters/trace/zipkin/exporter_test.go @@ -30,7 +30,6 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/trace" ) @@ -137,11 +136,11 @@ func TestExportSpans(t *testing.T) { spans := []*export.SpanData{ // parent { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{}, + ParentSpanID: trace.SpanID{}, SpanKind: trace.SpanKindServer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -153,11 +152,11 @@ func TestExportSpans(t *testing.T) { }, // child { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8}, }, - ParentSpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + ParentSpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanKind: trace.SpanKindServer, Name: "bar", StartTime: time.Date(2020, time.March, 11, 19, 24, 15, 0, time.UTC), diff --git a/exporters/trace/zipkin/model.go b/exporters/trace/zipkin/model.go index 30a5e5042..0355005a8 100644 --- a/exporters/trace/zipkin/model.go +++ b/exporters/trace/zipkin/model.go @@ -62,18 +62,18 @@ func toZipkinSpanContext(data *export.SpanData) zkmodel.SpanContext { } } -func toZipkinTraceID(traceID core.TraceID) zkmodel.TraceID { +func toZipkinTraceID(traceID trace.TraceID) zkmodel.TraceID { return zkmodel.TraceID{ High: binary.BigEndian.Uint64(traceID[:8]), Low: binary.BigEndian.Uint64(traceID[8:]), } } -func toZipkinID(spanID core.SpanID) zkmodel.ID { +func toZipkinID(spanID trace.SpanID) zkmodel.ID { return zkmodel.ID(binary.BigEndian.Uint64(spanID[:])) } -func toZipkinParentID(spanID core.SpanID) *zkmodel.ID { +func toZipkinParentID(spanID trace.SpanID) *zkmodel.ID { if spanID.IsValid() { id := toZipkinID(spanID) return &id diff --git a/exporters/trace/zipkin/model_test.go b/exporters/trace/zipkin/model_test.go index 52a021584..91ab082c7 100644 --- a/exporters/trace/zipkin/model_test.go +++ b/exporters/trace/zipkin/model_test.go @@ -32,11 +32,11 @@ func TestModelConversion(t *testing.T) { inputBatch := []*export.SpanData{ // typical span data { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindServer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -65,11 +65,11 @@ func TestModelConversion(t *testing.T) { // span data with no parent (same as typical, but has // invalid parent) { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{}, + ParentSpanID: trace.SpanID{}, SpanKind: trace.SpanKindServer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -97,11 +97,11 @@ func TestModelConversion(t *testing.T) { }, // span data of unspecified kind { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindUnspecified, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -129,11 +129,11 @@ func TestModelConversion(t *testing.T) { }, // span data of internal kind { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindInternal, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -161,11 +161,11 @@ func TestModelConversion(t *testing.T) { }, // span data of client kind { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindClient, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -193,11 +193,11 @@ func TestModelConversion(t *testing.T) { }, // span data of producer kind { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindProducer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -225,11 +225,11 @@ func TestModelConversion(t *testing.T) { }, // span data of consumer kind { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindConsumer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -257,11 +257,11 @@ func TestModelConversion(t *testing.T) { }, // span data with no events { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindServer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), @@ -276,11 +276,11 @@ func TestModelConversion(t *testing.T) { }, // span data with an "error" attribute set to "false" { - SpanContext: core.SpanContext{ - TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, + SpanContext: trace.SpanContext{ + TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, - ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, + ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, SpanKind: trace.SpanKindServer, Name: "foo", StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), diff --git a/internal/trace/mock_span.go b/internal/trace/mock_span.go index 89991eee4..f8f59459a 100644 --- a/internal/trace/mock_span.go +++ b/internal/trace/mock_span.go @@ -26,7 +26,7 @@ import ( // MockSpan is a mock span used in association with MockTracer for testing purpose only. type MockSpan struct { - sc core.SpanContext + sc apitrace.SpanContext tracer apitrace.Tracer Name string } @@ -35,9 +35,9 @@ var _ apitrace.Span = (*MockSpan)(nil) // SpanContext returns associated core.SpanContext. If the receiver is nil it returns // an empty core.SpanContext -func (ms *MockSpan) SpanContext() core.SpanContext { +func (ms *MockSpan) SpanContext() apitrace.SpanContext { if ms == nil { - return core.EmptySpanContext() + return apitrace.EmptySpanContext() } return ms.sc } diff --git a/internal/trace/mock_tracer.go b/internal/trace/mock_tracer.go index a15975439..4498434e8 100644 --- a/internal/trace/mock_tracer.go +++ b/internal/trace/mock_tracer.go @@ -20,7 +20,6 @@ import ( "encoding/binary" "sync/atomic" - "go.opentelemetry.io/otel/api/core" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/internal/trace/parent" ) @@ -62,15 +61,15 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Star op(&opts) } var span *MockSpan - var sc core.SpanContext + var sc apitrace.SpanContext parentSpanContext, _, _ := parent.GetSpanContextAndLinks(ctx, opts.NewRoot) if !parentSpanContext.IsValid() { - sc = core.SpanContext{} + sc = apitrace.SpanContext{} _, _ = rand.Read(sc.TraceID[:]) if mt.Sampled { - sc.TraceFlags = core.TraceFlagsSampled + sc.TraceFlags = apitrace.TraceFlagsSampled } } else { sc = parentSpanContext diff --git a/internal/trace/parent/parent.go b/internal/trace/parent/parent.go index 19184c947..7aac95088 100644 --- a/internal/trace/parent/parent.go +++ b/internal/trace/parent/parent.go @@ -22,7 +22,7 @@ import ( "go.opentelemetry.io/otel/api/trace" ) -func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanContext, bool, []trace.Link) { +func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (trace.SpanContext, bool, []trace.Link) { lsctx := trace.SpanFromContext(ctx).SpanContext() rsctx := trace.RemoteSpanContextFromContext(ctx) @@ -30,7 +30,7 @@ func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanC links := addLinkIfValid(nil, lsctx, "current") links = addLinkIfValid(links, rsctx, "remote") - return core.EmptySpanContext(), false, links + return trace.EmptySpanContext(), false, links } if lsctx.IsValid() { return lsctx, false, nil @@ -38,10 +38,10 @@ func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanC if rsctx.IsValid() { return rsctx, true, nil } - return core.EmptySpanContext(), false, nil + return trace.EmptySpanContext(), false, nil } -func addLinkIfValid(links []trace.Link, sc core.SpanContext, kind string) []trace.Link { +func addLinkIfValid(links []trace.Link, sc trace.SpanContext, kind string) []trace.Link { if !sc.IsValid() { return links } diff --git a/plugin/grpctrace/grpctrace.go b/plugin/grpctrace/grpctrace.go index 4efc9ccd8..9e27b2a9e 100644 --- a/plugin/grpctrace/grpctrace.go +++ b/plugin/grpctrace/grpctrace.go @@ -54,7 +54,7 @@ func Inject(ctx context.Context, metadata *metadata.MD) { // Extract returns the correlation context and span context that // another service encoded in the gRPC metadata object with Inject. // This function is meant to be used on incoming requests. -func Extract(ctx context.Context, metadata *metadata.MD) ([]core.KeyValue, core.SpanContext) { +func Extract(ctx context.Context, metadata *metadata.MD) ([]core.KeyValue, trace.SpanContext) { ctx = propagation.ExtractHTTP(ctx, global.Propagators(), &metadataSupplier{ metadata: metadata, }) diff --git a/plugin/httptrace/httptrace.go b/plugin/httptrace/httptrace.go index d8153dc12..70394027c 100644 --- a/plugin/httptrace/httptrace.go +++ b/plugin/httptrace/httptrace.go @@ -32,7 +32,7 @@ var ( ) // Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. -func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, core.SpanContext) { +func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, trace.SpanContext) { ctx = propagation.ExtractHTTP(ctx, global.Propagators(), req.Header) attrs := []core.KeyValue{ diff --git a/plugin/othttp/transport_test.go b/plugin/othttp/transport_test.go index 3d4dd577f..86e29adcb 100644 --- a/plugin/othttp/transport_test.go +++ b/plugin/othttp/transport_test.go @@ -22,7 +22,6 @@ import ( "net/http/httptest" "testing" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/trace" @@ -37,7 +36,7 @@ func TestTransportBasics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := propagation.ExtractHTTP(r.Context(), global.Propagators(), r.Header) span := trace.RemoteSpanContextFromContext(ctx) - tgtID, err := core.SpanIDFromHex(fmt.Sprintf("%016x", id)) + tgtID, err := trace.SpanIDFromHex(fmt.Sprintf("%016x", id)) if err != nil { t.Fatalf("Error converting id to SpanID: %s", err.Error()) } diff --git a/sdk/export/trace/trace.go b/sdk/export/trace/trace.go index 23ced06f4..f76067cf7 100644 --- a/sdk/export/trace/trace.go +++ b/sdk/export/trace/trace.go @@ -48,8 +48,8 @@ type SpanBatcher interface { // SpanData contains all the information collected by a span. type SpanData struct { - SpanContext core.SpanContext - ParentSpanID core.SpanID + SpanContext apitrace.SpanContext + ParentSpanID apitrace.SpanID SpanKind apitrace.SpanKind Name string StartTime time.Time diff --git a/sdk/trace/batch_span_processor_test.go b/sdk/trace/batch_span_processor_test.go index df77f3937..75adb1a3c 100644 --- a/sdk/trace/batch_span_processor_test.go +++ b/sdk/trace/batch_span_processor_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - "go.opentelemetry.io/otel/api/core" apitrace "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -203,7 +202,7 @@ func generateSpan(t *testing.T, parallel bool, tr apitrace.Tracer, option testOp for i := 0; i < option.genNumSpans; i++ { binary.BigEndian.PutUint64(sc.TraceID[0:8], uint64(i+1)) wg.Add(1) - f := func(sc core.SpanContext) { + f := func(sc apitrace.SpanContext) { ctx := apitrace.ContextWithRemoteSpanContext(context.Background(), sc) _, span := tr.Start(ctx, option.name) span.End() @@ -218,10 +217,10 @@ func generateSpan(t *testing.T, parallel bool, tr apitrace.Tracer, option testOp wg.Wait() } -func getSpanContext() core.SpanContext { - tid, _ := core.TraceIDFromHex("01020304050607080102040810203040") - sid, _ := core.SpanIDFromHex("0102040810203040") - return core.SpanContext{ +func getSpanContext() apitrace.SpanContext { + tid, _ := apitrace.TraceIDFromHex("01020304050607080102040810203040") + sid, _ := apitrace.SpanIDFromHex("0102040810203040") + return apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 0x1, diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index dad9a7531..9daaed5b6 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -18,7 +18,6 @@ import ( "context" "testing" - "go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/key" apitrace "go.opentelemetry.io/otel/api/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -134,8 +133,8 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { } func BenchmarkTraceID_DotString(b *testing.B) { - t, _ := core.TraceIDFromHex("0000000000000001000000000000002a") - sc := core.SpanContext{TraceID: t} + t, _ := apitrace.TraceIDFromHex("0000000000000001000000000000002a") + sc := apitrace.SpanContext{TraceID: t} want := "0000000000000001000000000000002a" for i := 0; i < b.N; i++ { @@ -146,7 +145,7 @@ func BenchmarkTraceID_DotString(b *testing.B) { } func BenchmarkSpanID_DotString(b *testing.B) { - sc := core.SpanContext{SpanID: core.SpanID{1}} + sc := apitrace.SpanContext{SpanID: apitrace.SpanID{1}} want := "0100000000000000" for i := 0; i < b.N; i++ { if got := sc.SpanID.String(); got != want { diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 028fd0787..056f03f8b 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -18,7 +18,8 @@ import ( "math/rand" "sync" - "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/sdk/trace/internal" ) @@ -30,20 +31,20 @@ type defaultIDGenerator struct { var _ internal.IDGenerator = &defaultIDGenerator{} // NewSpanID returns a non-zero span ID from a randomly-chosen sequence. -func (gen *defaultIDGenerator) NewSpanID() core.SpanID { +func (gen *defaultIDGenerator) NewSpanID() trace.SpanID { gen.Lock() defer gen.Unlock() - sid := core.SpanID{} + sid := trace.SpanID{} gen.randSource.Read(sid[:]) return sid } // NewTraceID returns a non-zero trace ID from a randomly-chosen sequence. // mu should be held while this function is called. -func (gen *defaultIDGenerator) NewTraceID() core.TraceID { +func (gen *defaultIDGenerator) NewTraceID() trace.TraceID { gen.Lock() defer gen.Unlock() - tid := core.TraceID{} + tid := trace.TraceID{} gen.randSource.Read(tid[:]) return tid } diff --git a/sdk/trace/internal/internal.go b/sdk/trace/internal/internal.go index 38190025f..d90d99471 100644 --- a/sdk/trace/internal/internal.go +++ b/sdk/trace/internal/internal.go @@ -15,10 +15,12 @@ // Package internal provides trace internals. package internal -import "go.opentelemetry.io/otel/api/core" +import ( + "go.opentelemetry.io/otel/api/trace" +) // IDGenerator allows custom generators for TraceId and SpanId. type IDGenerator interface { - NewTraceID() core.TraceID - NewSpanID() core.SpanID + NewTraceID() trace.TraceID + NewSpanID() trace.SpanID } diff --git a/sdk/trace/sampling.go b/sdk/trace/sampling.go index 30e0f1809..70438401a 100644 --- a/sdk/trace/sampling.go +++ b/sdk/trace/sampling.go @@ -30,9 +30,9 @@ type Sampler interface { // SamplingParameters contains the values passed to a Sampler. type SamplingParameters struct { - ParentContext core.SpanContext - TraceID core.TraceID - SpanID core.SpanID + ParentContext api.SpanContext + TraceID api.TraceID + SpanID api.SpanID Name string HasRemoteParent bool Kind api.SpanKind diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 5a83a183c..bed6bc4dc 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -17,18 +17,19 @@ package trace_test import ( "testing" - "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/api/trace" + sdktrace "go.opentelemetry.io/otel/sdk/trace" ) func TestAlwaysParentSampleWithParentSampled(t *testing.T) { sampler := sdktrace.AlwaysParentSample() - traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") - spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") - parentCtx := core.SpanContext{ + traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") + parentCtx := trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: core.TraceFlagsSampled, + TraceFlags: trace.TraceFlagsSampled, } if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled { t.Error("Sampling decision should be RecordAndSampled") @@ -37,9 +38,9 @@ func TestAlwaysParentSampleWithParentSampled(t *testing.T) { func TestAlwaysParentSampleWithParentNotSampled(t *testing.T) { sampler := sdktrace.AlwaysParentSample() - traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") - spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") - parentCtx := core.SpanContext{ + traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") + parentCtx := trace.SpanContext{ TraceID: traceID, SpanID: spanID, } diff --git a/sdk/trace/simple_span_processor_test.go b/sdk/trace/simple_span_processor_test.go index d6d209d63..a4cf64328 100644 --- a/sdk/trace/simple_span_processor_test.go +++ b/sdk/trace/simple_span_processor_test.go @@ -18,7 +18,6 @@ import ( "context" "testing" - "go.opentelemetry.io/otel/api/core" apitrace "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -58,9 +57,9 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) { tp.RegisterSpanProcessor(ssp) tr := tp.Tracer("SimpleSpanProcessor") - tid, _ := core.TraceIDFromHex("01020304050607080102040810203040") - sid, _ := core.SpanIDFromHex("0102040810203040") - sc := core.SpanContext{ + tid, _ := apitrace.TraceIDFromHex("01020304050607080102040810203040") + sid, _ := apitrace.SpanIDFromHex("0102040810203040") + sc := apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 0x1, diff --git a/sdk/trace/span.go b/sdk/trace/span.go index b1b1f3873..dc24d3c21 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -45,7 +45,7 @@ type span struct { // SpanContext, so that the trace ID is propagated. data *export.SpanData mu sync.Mutex // protects the contents of *data (but not the pointer value.) - spanContext core.SpanContext + spanContext apitrace.SpanContext // attributes are capped at configured limit. When the capacity is reached an oldest entry // is removed to create room for a new entry. @@ -67,9 +67,9 @@ type span struct { var _ apitrace.Span = &span{} -func (s *span) SpanContext() core.SpanContext { +func (s *span) SpanContext() apitrace.SpanContext { if s == nil { - return core.EmptySpanContext() + return apitrace.EmptySpanContext() } return s.spanContext } @@ -212,9 +212,9 @@ func (s *span) SetName(name string) { s.data.Name = name // SAMPLING noParent := !s.data.ParentSpanID.IsValid() - var ctx core.SpanContext + var ctx apitrace.SpanContext if noParent { - ctx = core.EmptySpanContext() + ctx = apitrace.EmptySpanContext() } else { // FIXME: Where do we get the parent context from? // From SpanStore? @@ -303,14 +303,14 @@ func (s *span) addChild() { s.mu.Unlock() } -func startSpanInternal(tr *tracer, name string, parent core.SpanContext, remoteParent bool, o apitrace.StartConfig) *span { +func startSpanInternal(tr *tracer, name string, parent apitrace.SpanContext, remoteParent bool, o apitrace.StartConfig) *span { var noParent bool span := &span{} span.spanContext = parent cfg := tr.provider.config.Load().(*Config) - if parent == core.EmptySpanContext() { + if parent == apitrace.EmptySpanContext() { span.spanContext.TraceID = cfg.IDGenerator.NewTraceID() noParent = true } @@ -370,7 +370,7 @@ func startSpanInternal(tr *tracer, name string, parent core.SpanContext, remoteP type samplingData struct { noParent bool remoteParent bool - parent core.SpanContext + parent apitrace.SpanContext name string cfg *Config span *span @@ -403,13 +403,13 @@ func makeSamplingDecision(data samplingData) SamplingResult { Links: data.links, }) if sampled.Decision == RecordAndSampled { - spanContext.TraceFlags |= core.TraceFlagsSampled + spanContext.TraceFlags |= apitrace.TraceFlagsSampled } else { - spanContext.TraceFlags &^= core.TraceFlagsSampled + spanContext.TraceFlags &^= apitrace.TraceFlagsSampled } return sampled } - if data.parent.TraceFlags&core.TraceFlagsSampled != 0 { + if data.parent.TraceFlags&apitrace.TraceFlagsSampled != 0 { return SamplingResult{Decision: RecordAndSampled} } return SamplingResult{Decision: NotRecord} diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 811d1fd66..84589d69a 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -38,13 +38,13 @@ import ( ) var ( - tid core.TraceID - sid core.SpanID + tid apitrace.TraceID + sid apitrace.SpanID ) func init() { - tid, _ = core.TraceIDFromHex("01020304050607080102040810203040") - sid, _ = core.SpanIDFromHex("0102040810203040") + tid, _ = apitrace.TraceIDFromHex("01020304050607080102040810203040") + sid, _ = apitrace.SpanIDFromHex("0102040810203040") } func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) { @@ -195,12 +195,12 @@ func TestSampling(t *testing.T) { for i := 0; i < total; i++ { ctx := context.Background() if tc.parent { - psc := core.SpanContext{ + psc := apitrace.SpanContext{ TraceID: idg.NewTraceID(), SpanID: idg.NewSpanID(), } if tc.sampledParent { - psc.TraceFlags = core.TraceFlagsSampled + psc.TraceFlags = apitrace.TraceFlagsSampled } ctx = apitrace.ContextWithRemoteSpanContext(ctx, psc) } @@ -231,7 +231,7 @@ func TestStartSpanWithParent(t *testing.T) { tr := tp.Tracer("SpanWithParent") ctx := context.Background() - sc1 := core.SpanContext{ + sc1 := apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 0x1, @@ -246,7 +246,7 @@ func TestStartSpanWithParent(t *testing.T) { t.Error(err) } - sc2 := core.SpanContext{ + sc2 := apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 0x1, @@ -283,7 +283,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -312,7 +312,7 @@ func TestSetSpanAttributes(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -347,7 +347,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -392,7 +392,7 @@ func TestEvents(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -442,7 +442,7 @@ func TestEventsOverLimit(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -469,8 +469,8 @@ func TestLinks(t *testing.T) { k2v2 := key.New("key2").String("value2") k3v3 := key.New("key3").String("value3") - sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} - sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} + sc1 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc2 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} span := startSpan(tp, "Links", apitrace.LinkedTo(sc1, key.New("key1").String("value1")), @@ -486,7 +486,7 @@ func TestLinks(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -508,9 +508,9 @@ func TestLinksOverLimit(t *testing.T) { te := &testExporter{} cfg := Config{MaxLinksPerSpan: 2} - sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} - sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} - sc3 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} + sc1 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc2 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc3 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) @@ -529,7 +529,7 @@ func TestLinksOverLimit(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -554,7 +554,7 @@ func TestSetSpanName(t *testing.T) { ctx := context.Background() want := "SpanName-1" - ctx = apitrace.ContextWithRemoteSpanContext(ctx, core.SpanContext{ + ctx = apitrace.ContextWithRemoteSpanContext(ctx, apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 1, @@ -582,7 +582,7 @@ func TestSetSpanStatus(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -604,8 +604,8 @@ func cmpDiff(x, y interface{}) string { cmp.AllowUnexported(export.Event{})) } -func remoteSpanContext() core.SpanContext { - return core.SpanContext{ +func remoteSpanContext() apitrace.SpanContext { + return apitrace.SpanContext{ TraceID: tid, SpanID: sid, TraceFlags: 1, @@ -614,7 +614,7 @@ func remoteSpanContext() core.SpanContext { // checkChild is test utility function that tests that c has fields set appropriately, // given that it is a child span of p. -func checkChild(p core.SpanContext, apiSpan apitrace.Span) error { +func checkChild(p apitrace.SpanContext, apiSpan apitrace.Span) error { s := apiSpan.(*span) if s == nil { return fmt.Errorf("got nil child span, want non-nil") @@ -681,7 +681,7 @@ func endSpan(te *testExporter, span apitrace.Span) (*export.SpanData, error) { if !got.SpanContext.SpanID.IsValid() { return nil, fmt.Errorf("exporting span: expected nonzero SpanID") } - got.SpanContext.SpanID = core.SpanID{} + got.SpanContext.SpanID = apitrace.SpanID{} if !checkTime(&got.StartTime) { return nil, fmt.Errorf("exporting span: expected nonzero StartTime") } @@ -833,12 +833,12 @@ func TestExecutionTracerTaskEnd(t *testing.T) { s.executionTracerTaskEnd = executionTracerTaskEnd spans = append(spans, s) // never sample - tID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f") - sID, _ := core.SpanIDFromHex("0001020304050607") + tID, _ := apitrace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f") + sID, _ := apitrace.SpanIDFromHex("0001020304050607") ctx := context.Background() ctx = apitrace.ContextWithRemoteSpanContext(ctx, - core.SpanContext{ + apitrace.SpanContext{ TraceID: tID, SpanID: sID, TraceFlags: 0, @@ -925,7 +925,7 @@ func TestRecordError(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -969,7 +969,7 @@ func TestRecordErrorWithStatus(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -1008,7 +1008,7 @@ func TestRecordErrorNil(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, @@ -1075,7 +1075,7 @@ func TestWithResource(t *testing.T) { } want := &export.SpanData{ - SpanContext: core.SpanContext{ + SpanContext: apitrace.SpanContext{ TraceID: tid, TraceFlags: 0x1, }, From bae2298a36dd491ede68934f76be5578d1b09505 Mon Sep 17 00:00:00 2001 From: tensorchen Date: Sat, 2 May 2020 20:23:09 +0800 Subject: [PATCH 2/3] Rename trace.TraceID & trace.TraceIDFromHex --- api/trace/always_off_sampler.go | 2 +- api/trace/always_off_sampler_test.go | 2 +- api/trace/always_on_sampler.go | 2 +- api/trace/always_on_sampler_test.go | 2 +- api/trace/b3_propagator.go | 4 +-- api/trace/sampler.go | 2 +- api/trace/span_context.go | 20 ++++++------ api/trace/span_context_test.go | 32 +++++++++---------- api/trace/testtrace/generator.go | 6 ++-- api/trace/testtrace/propagator_test.go | 2 +- ...trace_context_propagator_benchmark_test.go | 2 +- .../trace_context_propagator_test.go | 4 +-- api/trace/testtrace/tracer.go | 2 +- api/trace/trace_context_propagator.go | 2 +- bridge/opentracing/internal/mock.go | 8 ++--- bridge/opentracing/mix_test.go | 8 ++--- .../otlp/internal/transform/span_test.go | 6 ++-- exporters/otlp/otlp_span_test.go | 6 ++-- exporters/trace/jaeger/jaeger_test.go | 4 +-- exporters/trace/stdout/stdout_test.go | 2 +- exporters/trace/zipkin/exporter_test.go | 4 +-- exporters/trace/zipkin/model.go | 2 +- exporters/trace/zipkin/model_test.go | 18 +++++------ sdk/trace/batch_span_processor_test.go | 2 +- sdk/trace/benchmark_test.go | 2 +- sdk/trace/id_generator.go | 4 +-- sdk/trace/internal/internal.go | 2 +- sdk/trace/sampling.go | 2 +- sdk/trace/sampling_test.go | 4 +-- sdk/trace/simple_span_processor_test.go | 2 +- sdk/trace/trace_test.go | 16 +++++----- 31 files changed, 88 insertions(+), 88 deletions(-) diff --git a/api/trace/always_off_sampler.go b/api/trace/always_off_sampler.go index dbc82fea8..22116f299 100644 --- a/api/trace/always_off_sampler.go +++ b/api/trace/always_off_sampler.go @@ -32,7 +32,7 @@ type alwaysOffSampler struct{} func (ns alwaysOffSampler) ShouldSample( _ SpanContext, _ bool, - _ TraceID, + _ ID, _ SpanID, _ string, _ SpanKind, diff --git a/api/trace/always_off_sampler_test.go b/api/trace/always_off_sampler_test.go index ff0065c70..cc87af41f 100644 --- a/api/trace/always_off_sampler_test.go +++ b/api/trace/always_off_sampler_test.go @@ -24,7 +24,7 @@ import ( func TestNeverSamperShouldSample(t *testing.T) { gotD := AlwaysOffSampler().ShouldSample( - SpanContext{}, false, TraceID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) + SpanContext{}, false, ID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) wantD := Decision{Sampled: false} if diff := cmp.Diff(wantD, gotD); diff != "" { t.Errorf("Decision: +got, -want%v", diff) diff --git a/api/trace/always_on_sampler.go b/api/trace/always_on_sampler.go index b92d2b0e4..05e1d8050 100644 --- a/api/trace/always_on_sampler.go +++ b/api/trace/always_on_sampler.go @@ -32,7 +32,7 @@ type alwaysOnSampler struct{} func (as alwaysOnSampler) ShouldSample( _ SpanContext, _ bool, - _ TraceID, + _ ID, _ SpanID, _ string, _ SpanKind, diff --git a/api/trace/always_on_sampler_test.go b/api/trace/always_on_sampler_test.go index 2cf033560..88f83f36a 100644 --- a/api/trace/always_on_sampler_test.go +++ b/api/trace/always_on_sampler_test.go @@ -24,7 +24,7 @@ import ( func TestAlwaysOnSamplerShouldSample(t *testing.T) { gotD := AlwaysOnSampler().ShouldSample( - SpanContext{}, false, TraceID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) + SpanContext{}, false, ID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) wantD := Decision{Sampled: true} if diff := cmp.Diff(wantD, gotD); diff != "" { t.Errorf("Decision: +got, -want%v", diff) diff --git a/api/trace/b3_propagator.go b/api/trace/b3_propagator.go index 679ef9eaa..349a4d274 100644 --- a/api/trace/b3_propagator.go +++ b/api/trace/b3_propagator.go @@ -88,7 +88,7 @@ func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) con } func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext { - tid, err := TraceIDFromHex(supplier.Get(B3TraceIDHeader)) + tid, err := IDFromHex(supplier.Get(B3TraceIDHeader)) if err != nil { return EmptySpanContext() } @@ -139,7 +139,7 @@ func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) SpanContext } var err error - sc.TraceID, err = TraceIDFromHex(parts[0]) + sc.TraceID, err = IDFromHex(parts[0]) if err != nil { return EmptySpanContext() } diff --git a/api/trace/sampler.go b/api/trace/sampler.go index a3709797e..91df24ed6 100644 --- a/api/trace/sampler.go +++ b/api/trace/sampler.go @@ -23,7 +23,7 @@ type Sampler interface { ShouldSample( sc SpanContext, remote bool, - traceID TraceID, + traceID ID, spanID SpanID, spanName string, spanKind SpanKind, diff --git a/api/trace/span_context.go b/api/trace/span_context.go index 969dbdf38..309cd6379 100644 --- a/api/trace/span_context.go +++ b/api/trace/span_context.go @@ -44,26 +44,26 @@ func (e errorConst) Error() string { return string(e) } -// TraceID is a unique identity of a trace. -type TraceID [16]byte +// ID is a unique identity of a trace. +type ID [16]byte -var nilTraceID TraceID +var nilTraceID ID var _ json.Marshaler = nilTraceID // IsValid checks whether the trace ID is valid. A valid trace ID does // not consist of zeros only. -func (t TraceID) IsValid() bool { +func (t ID) IsValid() bool { return !bytes.Equal(t[:], nilTraceID[:]) } // MarshalJSON implements a custom marshal function to encode TraceID // as a hex string. -func (t TraceID) MarshalJSON() ([]byte, error) { +func (t ID) MarshalJSON() ([]byte, error) { return json.Marshal(t.String()) } // String returns the hex string representation form of a TraceID -func (t TraceID) String() string { +func (t ID) String() string { return hex.EncodeToString(t[:]) } @@ -90,11 +90,11 @@ func (s SpanID) String() string { return hex.EncodeToString(s[:]) } -// TraceIDFromHex returns a TraceID from a hex string if it is compliant +// IDFromHex returns a TraceID from a hex string if it is compliant // with the w3c trace-context specification. // See more at https://www.w3.org/TR/trace-context/#trace-id -func TraceIDFromHex(h string) (TraceID, error) { - t := TraceID{} +func IDFromHex(h string) (ID, error) { + t := ID{} if len(h) != 32 { return t, ErrInvalidTraceIDLength } @@ -152,7 +152,7 @@ func decodeHex(h string, b []byte) error { // SpanContext contains basic information about the span - its trace // ID, span ID and trace flags. type SpanContext struct { - TraceID TraceID + TraceID ID SpanID SpanID TraceFlags byte } diff --git a/api/trace/span_context_test.go b/api/trace/span_context_test.go index 16b07fcdf..b94c1b1b0 100644 --- a/api/trace/span_context_test.go +++ b/api/trace/span_context_test.go @@ -23,7 +23,7 @@ import ( func TestIsValid(t *testing.T) { for _, testcase := range []struct { name string - tid trace.TraceID + tid trace.ID sid trace.SpanID want bool }{ @@ -34,17 +34,17 @@ func TestIsValid(t *testing.T) { want: true, }, { name: "SpanContext.IsValid() returns false if sc has neither an Trace ID nor Span ID", - tid: trace.TraceID([16]byte{}), + tid: trace.ID([16]byte{}), sid: [8]byte{}, want: false, }, { name: "SpanContext.IsValid() returns false if sc has a Span ID but not a Trace ID", - tid: trace.TraceID([16]byte{}), + tid: trace.ID([16]byte{}), sid: [8]byte{42}, want: false, }, { name: "SpanContext.IsValid() returns false if sc has a Trace ID but not a Span ID", - tid: trace.TraceID([16]byte{1}), + tid: trace.ID([16]byte{1}), sid: [8]byte{}, want: false, }, @@ -66,12 +66,12 @@ func TestIsValidFromHex(t *testing.T) { for _, testcase := range []struct { name string hex string - tid trace.TraceID + tid trace.ID valid bool }{ { name: "Valid TraceID", - tid: trace.TraceID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}), + tid: trace.ID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}), hex: "80f198ee56343ba864fe8b2a57d3eff7", valid: true, }, { @@ -89,7 +89,7 @@ func TestIsValidFromHex(t *testing.T) { }, } { t.Run(testcase.name, func(t *testing.T) { - tid, err := trace.TraceIDFromHex(testcase.hex) + tid, err := trace.IDFromHex(testcase.hex) if testcase.valid && err != nil { t.Errorf("Expected TraceID %s to be valid but end with error %s", testcase.hex, err.Error()) @@ -109,16 +109,16 @@ func TestIsValidFromHex(t *testing.T) { func TestHasTraceID(t *testing.T) { for _, testcase := range []struct { name string - tid trace.TraceID + tid trace.ID want bool }{ { name: "SpanContext.HasTraceID() returns true if both Low and High are nonzero", - tid: trace.TraceID([16]byte{1}), + tid: trace.ID([16]byte{1}), want: true, }, { name: "SpanContext.HasTraceID() returns false if neither Low nor High are nonzero", - tid: trace.TraceID{}, + tid: trace.ID{}, want: false, }, } { @@ -168,20 +168,20 @@ func TestSpanContextIsSampled(t *testing.T) { { name: "sampled", sc: trace.SpanContext{ - TraceID: trace.TraceID([16]byte{1}), + TraceID: trace.ID([16]byte{1}), TraceFlags: trace.TraceFlagsSampled, }, want: true, }, { name: "sampled plus unused", sc: trace.SpanContext{ - TraceID: trace.TraceID([16]byte{1}), + TraceID: trace.ID([16]byte{1}), TraceFlags: trace.TraceFlagsSampled | trace.TraceFlagsUnused, }, want: true, }, { name: "not sampled/default", - sc: trace.SpanContext{TraceID: trace.TraceID{}}, + sc: trace.SpanContext{TraceID: trace.ID{}}, want: false, }, } { @@ -197,17 +197,17 @@ func TestSpanContextIsSampled(t *testing.T) { func TestStringTraceID(t *testing.T) { for _, testcase := range []struct { name string - tid trace.TraceID + tid trace.ID want string }{ { name: "TraceID.String returns string representation of self.TraceID values > 0", - tid: trace.TraceID([16]byte{255}), + tid: trace.ID([16]byte{255}), want: "ff000000000000000000000000000000", }, { name: "TraceID.String returns string representation of self.TraceID values == 0", - tid: trace.TraceID([16]byte{}), + tid: trace.ID([16]byte{}), want: "00000000000000000000000000000000", }, } { diff --git a/api/trace/testtrace/generator.go b/api/trace/testtrace/generator.go index 5edf85fee..35a09b5e8 100644 --- a/api/trace/testtrace/generator.go +++ b/api/trace/testtrace/generator.go @@ -22,7 +22,7 @@ import ( ) type Generator interface { - TraceID() trace.TraceID + TraceID() trace.ID SpanID() trace.SpanID } @@ -41,7 +41,7 @@ func NewCountGenerator() *CountGenerator { return &CountGenerator{} } -func (g *CountGenerator) TraceID() trace.TraceID { +func (g *CountGenerator) TraceID() trace.ID { g.lock.Lock() defer g.lock.Unlock() @@ -51,7 +51,7 @@ func (g *CountGenerator) TraceID() trace.TraceID { g.traceIDLow++ } - var traceID trace.TraceID + var traceID trace.ID binary.BigEndian.PutUint64(traceID[0:8], g.traceIDLow) binary.BigEndian.PutUint64(traceID[8:], g.traceIDHigh) diff --git a/api/trace/testtrace/propagator_test.go b/api/trace/testtrace/propagator_test.go index 0f995188c..09b75bcc8 100644 --- a/api/trace/testtrace/propagator_test.go +++ b/api/trace/testtrace/propagator_test.go @@ -32,7 +32,7 @@ type outOfThinAirPropagator struct { var _ propagation.HTTPPropagator = outOfThinAirPropagator{} func (p outOfThinAirPropagator) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context { - traceID, err := trace.TraceIDFromHex("938753245abe987f098c0987a9873987") + traceID, err := trace.IDFromHex("938753245abe987f098c0987a9873987") require.NoError(p.t, err) spanID, err := trace.SpanIDFromHex("2345f98c0987a09d") require.NoError(p.t, err) diff --git a/api/trace/testtrace/trace_context_propagator_benchmark_test.go b/api/trace/testtrace/trace_context_propagator_benchmark_test.go index 54e05fd9a..413aadad3 100644 --- a/api/trace/testtrace/trace_context_propagator_benchmark_test.go +++ b/api/trace/testtrace/trace_context_propagator_benchmark_test.go @@ -39,7 +39,7 @@ func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) { b.Run("SampledSpanContext", func(b *testing.B) { var id uint64 spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") - traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") mockTracer := &mocktrace.MockTracer{ Sampled: false, diff --git a/api/trace/testtrace/trace_context_propagator_test.go b/api/trace/testtrace/trace_context_propagator_test.go index 83ea7d6b6..ddda05969 100644 --- a/api/trace/testtrace/trace_context_propagator_test.go +++ b/api/trace/testtrace/trace_context_propagator_test.go @@ -31,8 +31,8 @@ var ( spanID = mustSpanIDFromHex("00f067aa0ba902b7") ) -func mustTraceIDFromHex(s string) (t trace.TraceID) { - t, _ = trace.TraceIDFromHex(s) +func mustTraceIDFromHex(s string) (t trace.ID) { + t, _ = trace.IDFromHex(s) return } diff --git a/api/trace/testtrace/tracer.go b/api/trace/testtrace/tracer.go index eb6b78950..49dfdd453 100644 --- a/api/trace/testtrace/tracer.go +++ b/api/trace/testtrace/tracer.go @@ -51,7 +51,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti opt(&c) } - var traceID trace.TraceID + var traceID trace.ID var parentSpanID trace.SpanID parentSpanContext, _, links := parent.GetSpanContextAndLinks(ctx, c.NewRoot) diff --git a/api/trace/trace_context_propagator.go b/api/trace/trace_context_propagator.go index 685107da3..dfb11ed00 100644 --- a/api/trace/trace_context_propagator.go +++ b/api/trace/trace_context_propagator.go @@ -101,7 +101,7 @@ func (TraceContext) extract(supplier propagation.HTTPSupplier) SpanContext { var sc SpanContext - sc.TraceID, err = TraceIDFromHex(sections[1][:32]) + sc.TraceID, err = IDFromHex(sections[1][:32]) if err != nil { return EmptySpanContext() } diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index e3e30edc5..e3f8bd27b 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -49,7 +49,7 @@ type MockContextKeyValue struct { type MockTracer struct { Resources otelcorrelation.Map FinishedSpans []*MockSpan - SpareTraceIDs []oteltrace.TraceID + SpareTraceIDs []oteltrace.ID SpareSpanIDs []oteltrace.SpanID SpareContextKeyValues []MockContextKeyValue @@ -126,7 +126,7 @@ func (t *MockTracer) addSpareContextValue(ctx context.Context) context.Context { return ctx } -func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.TraceID { +func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.ID { if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() { return parent.TraceID } @@ -175,11 +175,11 @@ func (t *MockTracer) getRandSpanID() oteltrace.SpanID { return sid } -func (t *MockTracer) getRandTraceID() oteltrace.TraceID { +func (t *MockTracer) getRandTraceID() oteltrace.ID { t.randLock.Lock() defer t.randLock.Unlock() - tid := oteltrace.TraceID{} + tid := oteltrace.ID{} t.rand.Read(tid[:]) return tid diff --git a/bridge/opentracing/mix_test.go b/bridge/opentracing/mix_test.go index fd9bf4f8d..f1f4dd44e 100644 --- a/bridge/opentracing/mix_test.go +++ b/bridge/opentracing/mix_test.go @@ -143,7 +143,7 @@ func TestMixedAPIs(t *testing.T) { // simple test type simpleTest struct { - traceID oteltrace.TraceID + traceID oteltrace.ID spanIDs []oteltrace.SpanID } @@ -178,7 +178,7 @@ func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context { // current/active span test type currentActiveSpanTest struct { - traceID oteltrace.TraceID + traceID oteltrace.ID spanIDs []oteltrace.SpanID recordedCurrentOtelSpanIDs []oteltrace.SpanID @@ -614,7 +614,7 @@ func generateBaggageKeys(key string) (otKey, otelKey string) { // helpers -func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID oteltrace.TraceID, expectedSpanIDs []oteltrace.SpanID) { +func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID oteltrace.ID, expectedSpanIDs []oteltrace.SpanID) { expectedSpanCount := len(expectedSpanIDs) // reverse spanIDs, since first span ID belongs to root, that @@ -661,7 +661,7 @@ func reverse(length int, swap func(i, j int)) { } } -func simpleTraceID() oteltrace.TraceID { +func simpleTraceID() oteltrace.ID { return [16]byte{123, 42} } diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go index 16a0cee20..90ed5d2fb 100644 --- a/exporters/otlp/internal/transform/span_test.go +++ b/exporters/otlp/internal/transform/span_test.go @@ -271,7 +271,7 @@ func TestSpanData(t *testing.T) { endTime := startTime.Add(10 * time.Second) spanData := &export.SpanData{ SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: apitrace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: apitrace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, SpanKind: apitrace.SpanKindServer, @@ -294,7 +294,7 @@ func TestSpanData(t *testing.T) { Links: []apitrace.Link{ { SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, + TraceID: apitrace.ID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, TraceFlags: 0, }, @@ -304,7 +304,7 @@ func TestSpanData(t *testing.T) { }, { SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, + TraceID: apitrace.ID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, TraceFlags: 0, }, diff --git a/exporters/otlp/otlp_span_test.go b/exporters/otlp/otlp_span_test.go index 32511997c..22e1ba71d 100644 --- a/exporters/otlp/otlp_span_test.go +++ b/exporters/otlp/otlp_span_test.go @@ -82,7 +82,7 @@ func TestExportSpans(t *testing.T) { []*tracesdk.SpanData{ { SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), + TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), TraceFlags: byte(1), }, @@ -100,7 +100,7 @@ func TestExportSpans(t *testing.T) { }, { SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), + TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2}), TraceFlags: byte(1), }, @@ -119,7 +119,7 @@ func TestExportSpans(t *testing.T) { }, { SpanContext: apitrace.SpanContext{ - TraceID: apitrace.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), + TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), TraceFlags: byte(1), }, diff --git a/exporters/trace/jaeger/jaeger_test.go b/exporters/trace/jaeger/jaeger_test.go index 64a6bafae..bb234d8e8 100644 --- a/exporters/trace/jaeger/jaeger_test.go +++ b/exporters/trace/jaeger/jaeger_test.go @@ -191,10 +191,10 @@ func TestNewRawExporterWithAgentShouldFailIfEndpointInvalid(t *testing.T) { func Test_spanDataToThrift(t *testing.T) { now := time.Now() - traceID, _ := apitrace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") + traceID, _ := apitrace.IDFromHex("0102030405060708090a0b0c0d0e0f10") spanID, _ := apitrace.SpanIDFromHex("0102030405060708") - linkTraceID, _ := apitrace.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11") + linkTraceID, _ := apitrace.IDFromHex("0102030405060709090a0b0c0d0e0f11") linkSpanID, _ := apitrace.SpanIDFromHex("0102030405060709") eventNameValue := "event-test" diff --git a/exporters/trace/stdout/stdout_test.go b/exporters/trace/stdout/stdout_test.go index 35b17faac..f95edf014 100644 --- a/exporters/trace/stdout/stdout_test.go +++ b/exporters/trace/stdout/stdout_test.go @@ -40,7 +40,7 @@ func TestExporter_ExportSpan(t *testing.T) { // setup test span now := time.Now() - traceID, _ := trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") + traceID, _ := trace.IDFromHex("0102030405060708090a0b0c0d0e0f10") spanID, _ := trace.SpanIDFromHex("0102030405060708") keyValue := "value" doubleValue := 123.456 diff --git a/exporters/trace/zipkin/exporter_test.go b/exporters/trace/zipkin/exporter_test.go index bbb0f220b..76b78a7cc 100644 --- a/exporters/trace/zipkin/exporter_test.go +++ b/exporters/trace/zipkin/exporter_test.go @@ -137,7 +137,7 @@ func TestExportSpans(t *testing.T) { // parent { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{}, @@ -153,7 +153,7 @@ func TestExportSpans(t *testing.T) { // child { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8}, }, ParentSpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, diff --git a/exporters/trace/zipkin/model.go b/exporters/trace/zipkin/model.go index 0355005a8..4c2efb3c3 100644 --- a/exporters/trace/zipkin/model.go +++ b/exporters/trace/zipkin/model.go @@ -62,7 +62,7 @@ func toZipkinSpanContext(data *export.SpanData) zkmodel.SpanContext { } } -func toZipkinTraceID(traceID trace.TraceID) zkmodel.TraceID { +func toZipkinTraceID(traceID trace.ID) zkmodel.TraceID { return zkmodel.TraceID{ High: binary.BigEndian.Uint64(traceID[:8]), Low: binary.BigEndian.Uint64(traceID[8:]), diff --git a/exporters/trace/zipkin/model_test.go b/exporters/trace/zipkin/model_test.go index 91ab082c7..64f01fbe8 100644 --- a/exporters/trace/zipkin/model_test.go +++ b/exporters/trace/zipkin/model_test.go @@ -33,7 +33,7 @@ func TestModelConversion(t *testing.T) { // typical span data { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -66,7 +66,7 @@ func TestModelConversion(t *testing.T) { // invalid parent) { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{}, @@ -98,7 +98,7 @@ func TestModelConversion(t *testing.T) { // span data of unspecified kind { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -130,7 +130,7 @@ func TestModelConversion(t *testing.T) { // span data of internal kind { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -162,7 +162,7 @@ func TestModelConversion(t *testing.T) { // span data of client kind { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -194,7 +194,7 @@ func TestModelConversion(t *testing.T) { // span data of producer kind { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -226,7 +226,7 @@ func TestModelConversion(t *testing.T) { // span data of consumer kind { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -258,7 +258,7 @@ func TestModelConversion(t *testing.T) { // span data with no events { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, @@ -277,7 +277,7 @@ func TestModelConversion(t *testing.T) { // span data with an "error" attribute set to "false" { SpanContext: trace.SpanContext{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, + TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, }, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, diff --git a/sdk/trace/batch_span_processor_test.go b/sdk/trace/batch_span_processor_test.go index 75adb1a3c..9dcd086aa 100644 --- a/sdk/trace/batch_span_processor_test.go +++ b/sdk/trace/batch_span_processor_test.go @@ -218,7 +218,7 @@ func generateSpan(t *testing.T, parallel bool, tr apitrace.Tracer, option testOp } func getSpanContext() apitrace.SpanContext { - tid, _ := apitrace.TraceIDFromHex("01020304050607080102040810203040") + tid, _ := apitrace.IDFromHex("01020304050607080102040810203040") sid, _ := apitrace.SpanIDFromHex("0102040810203040") return apitrace.SpanContext{ TraceID: tid, diff --git a/sdk/trace/benchmark_test.go b/sdk/trace/benchmark_test.go index 9daaed5b6..1690d09f7 100644 --- a/sdk/trace/benchmark_test.go +++ b/sdk/trace/benchmark_test.go @@ -133,7 +133,7 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { } func BenchmarkTraceID_DotString(b *testing.B) { - t, _ := apitrace.TraceIDFromHex("0000000000000001000000000000002a") + t, _ := apitrace.IDFromHex("0000000000000001000000000000002a") sc := apitrace.SpanContext{TraceID: t} want := "0000000000000001000000000000002a" diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 056f03f8b..18a900a6f 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -41,10 +41,10 @@ func (gen *defaultIDGenerator) NewSpanID() trace.SpanID { // NewTraceID returns a non-zero trace ID from a randomly-chosen sequence. // mu should be held while this function is called. -func (gen *defaultIDGenerator) NewTraceID() trace.TraceID { +func (gen *defaultIDGenerator) NewTraceID() trace.ID { gen.Lock() defer gen.Unlock() - tid := trace.TraceID{} + tid := trace.ID{} gen.randSource.Read(tid[:]) return tid } diff --git a/sdk/trace/internal/internal.go b/sdk/trace/internal/internal.go index d90d99471..d82d778fd 100644 --- a/sdk/trace/internal/internal.go +++ b/sdk/trace/internal/internal.go @@ -21,6 +21,6 @@ import ( // IDGenerator allows custom generators for TraceId and SpanId. type IDGenerator interface { - NewTraceID() trace.TraceID + NewTraceID() trace.ID NewSpanID() trace.SpanID } diff --git a/sdk/trace/sampling.go b/sdk/trace/sampling.go index 70438401a..3f33a4733 100644 --- a/sdk/trace/sampling.go +++ b/sdk/trace/sampling.go @@ -31,7 +31,7 @@ type Sampler interface { // SamplingParameters contains the values passed to a Sampler. type SamplingParameters struct { ParentContext api.SpanContext - TraceID api.TraceID + TraceID api.ID SpanID api.SpanID Name string HasRemoteParent bool diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index bed6bc4dc..6e0a8f540 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -24,7 +24,7 @@ import ( func TestAlwaysParentSampleWithParentSampled(t *testing.T) { sampler := sdktrace.AlwaysParentSample() - traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") parentCtx := trace.SpanContext{ TraceID: traceID, @@ -38,7 +38,7 @@ func TestAlwaysParentSampleWithParentSampled(t *testing.T) { func TestAlwaysParentSampleWithParentNotSampled(t *testing.T) { sampler := sdktrace.AlwaysParentSample() - traceID, _ := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") + traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7") parentCtx := trace.SpanContext{ TraceID: traceID, diff --git a/sdk/trace/simple_span_processor_test.go b/sdk/trace/simple_span_processor_test.go index a4cf64328..16fe74234 100644 --- a/sdk/trace/simple_span_processor_test.go +++ b/sdk/trace/simple_span_processor_test.go @@ -57,7 +57,7 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) { tp.RegisterSpanProcessor(ssp) tr := tp.Tracer("SimpleSpanProcessor") - tid, _ := apitrace.TraceIDFromHex("01020304050607080102040810203040") + tid, _ := apitrace.IDFromHex("01020304050607080102040810203040") sid, _ := apitrace.SpanIDFromHex("0102040810203040") sc := apitrace.SpanContext{ TraceID: tid, diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 84589d69a..137e85f22 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -38,12 +38,12 @@ import ( ) var ( - tid apitrace.TraceID + tid apitrace.ID sid apitrace.SpanID ) func init() { - tid, _ = apitrace.TraceIDFromHex("01020304050607080102040810203040") + tid, _ = apitrace.IDFromHex("01020304050607080102040810203040") sid, _ = apitrace.SpanIDFromHex("0102040810203040") } @@ -469,8 +469,8 @@ func TestLinks(t *testing.T) { k2v2 := key.New("key2").String("value2") k3v3 := key.New("key3").String("value3") - sc1 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} - sc2 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} span := startSpan(tp, "Links", apitrace.LinkedTo(sc1, key.New("key1").String("value1")), @@ -508,9 +508,9 @@ func TestLinksOverLimit(t *testing.T) { te := &testExporter{} cfg := Config{MaxLinksPerSpan: 2} - sc1 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} - sc2 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} - sc3 := apitrace.SpanContext{TraceID: apitrace.TraceID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} + sc3 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}} tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) @@ -833,7 +833,7 @@ func TestExecutionTracerTaskEnd(t *testing.T) { s.executionTracerTaskEnd = executionTracerTaskEnd spans = append(spans, s) // never sample - tID, _ := apitrace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f") + tID, _ := apitrace.IDFromHex("0102030405060708090a0b0c0d0e0f") sID, _ := apitrace.SpanIDFromHex("0001020304050607") ctx := context.Background() From 2ffbd869d7ca492952ac0e3435579b45ee28412f Mon Sep 17 00:00:00 2001 From: tensorchen Date: Wed, 6 May 2020 01:41:54 +0800 Subject: [PATCH 3/3] Rename TraceFlagsSampled, TraceFlagsUnused --- api/trace/b3_propagator.go | 14 ++++++------- api/trace/span_context.go | 6 +++--- api/trace/span_context_test.go | 4 ++-- .../testtrace/b3_propagator_data_test.go | 20 +++++++++---------- ...trace_context_propagator_benchmark_test.go | 2 +- .../trace_context_propagator_test.go | 14 ++++++------- api/trace/trace_context_propagator.go | 4 ++-- internal/trace/mock_tracer.go | 2 +- sdk/trace/sampling_test.go | 2 +- sdk/trace/span.go | 6 +++--- sdk/trace/trace_test.go | 2 +- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/api/trace/b3_propagator.go b/api/trace/b3_propagator.go index 349a4d274..fe78f8727 100644 --- a/api/trace/b3_propagator.go +++ b/api/trace/b3_propagator.go @@ -56,7 +56,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) { return } if b3.SingleHeader { - sampled := sc.TraceFlags & TraceFlagsSampled + sampled := sc.TraceFlags & FlagsSampled supplier.Set(B3SingleHeader, fmt.Sprintf("%s-%s-%.1d", sc.TraceID, sc.SpanID, sampled)) } else { @@ -105,8 +105,8 @@ func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext { if !ok { return EmptySpanContext() } - if debug == TraceFlagsSampled { - sampled = TraceFlagsSampled + if debug == FlagsSampled { + sampled = FlagsSampled } sc := SpanContext{ @@ -176,14 +176,14 @@ func (b3 B3) extractSampledState(sampled string) (flag byte, ok bool) { case "", "0": return 0, true case "1": - return TraceFlagsSampled, true + return FlagsSampled, true case "true": if !b3.SingleHeader { - return TraceFlagsSampled, true + return FlagsSampled, true } case "d": if b3.SingleHeader { - return TraceFlagsSampled, true + return FlagsSampled, true } } return 0, false @@ -195,7 +195,7 @@ func (b3 B3) extracDebugFlag(debug string) (flag byte, ok bool) { case "", "0": return 0, true case "1": - return TraceFlagsSampled, true + return FlagsSampled, true } return 0, false } diff --git a/api/trace/span_context.go b/api/trace/span_context.go index 309cd6379..b15975568 100644 --- a/api/trace/span_context.go +++ b/api/trace/span_context.go @@ -24,10 +24,10 @@ const ( traceFlagsBitMaskSampled = byte(0x01) traceFlagsBitMaskUnused = byte(0xFE) - // TraceFlagsSampled is a byte with sampled bit set. It is a convenient value initializer + // FlagsSampled is a byte with sampled bit set. It is a convenient value initializer // for SpanContext TraceFlags field when a trace is sampled. - TraceFlagsSampled = traceFlagsBitMaskSampled - TraceFlagsUnused = traceFlagsBitMaskUnused + FlagsSampled = traceFlagsBitMaskSampled + FlagsUnused = traceFlagsBitMaskUnused ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase" diff --git a/api/trace/span_context_test.go b/api/trace/span_context_test.go index b94c1b1b0..74a314bd3 100644 --- a/api/trace/span_context_test.go +++ b/api/trace/span_context_test.go @@ -169,14 +169,14 @@ func TestSpanContextIsSampled(t *testing.T) { name: "sampled", sc: trace.SpanContext{ TraceID: trace.ID([16]byte{1}), - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, want: true, }, { name: "sampled plus unused", sc: trace.SpanContext{ TraceID: trace.ID([16]byte{1}), - TraceFlags: trace.TraceFlagsSampled | trace.TraceFlagsUnused, + TraceFlags: trace.FlagsSampled | trace.FlagsUnused, }, want: true, }, { diff --git a/api/trace/testtrace/b3_propagator_data_test.go b/api/trace/testtrace/b3_propagator_data_test.go index c7a1abc41..6cb4a092c 100644 --- a/api/trace/testtrace/b3_propagator_data_test.go +++ b/api/trace/testtrace/b3_propagator_data_test.go @@ -58,7 +58,7 @@ var extractMultipleHeaders = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -71,7 +71,7 @@ var extractMultipleHeaders = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -84,7 +84,7 @@ var extractMultipleHeaders = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -101,7 +101,7 @@ var extractMultipleHeaders = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -115,7 +115,7 @@ var extractMultipleHeaders = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -156,7 +156,7 @@ var extractSingleHeader = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -167,7 +167,7 @@ var extractSingleHeader = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -178,7 +178,7 @@ var extractSingleHeader = []extractTest{ wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -446,7 +446,7 @@ var injectB3MultipleHeader = []injectTest{ parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, wantHeaders: map[string]string{ trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", @@ -496,7 +496,7 @@ var injectB3SingleleHeader = []injectTest{ parentSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, wantHeaders: map[string]string{ trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1", diff --git a/api/trace/testtrace/trace_context_propagator_benchmark_test.go b/api/trace/testtrace/trace_context_propagator_benchmark_test.go index 413aadad3..f6ebc4d85 100644 --- a/api/trace/testtrace/trace_context_propagator_benchmark_test.go +++ b/api/trace/testtrace/trace_context_propagator_benchmark_test.go @@ -49,7 +49,7 @@ func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) { sc := trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, } ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc) ctx, _ = mockTracer.Start(ctx, "inject") diff --git a/api/trace/testtrace/trace_context_propagator_test.go b/api/trace/testtrace/trace_context_propagator_test.go index 513d63147..2a8fea2fc 100644 --- a/api/trace/testtrace/trace_context_propagator_test.go +++ b/api/trace/testtrace/trace_context_propagator_test.go @@ -62,7 +62,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -71,7 +71,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -80,7 +80,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -97,7 +97,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -106,7 +106,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, { @@ -115,7 +115,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) { wantSc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, }, } @@ -240,7 +240,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) { sc: trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, }, wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01", }, diff --git a/api/trace/trace_context_propagator.go b/api/trace/trace_context_propagator.go index 2792e91b3..d8263745e 100644 --- a/api/trace/trace_context_propagator.go +++ b/api/trace/trace_context_propagator.go @@ -62,7 +62,7 @@ func (TraceContext) Inject(ctx context.Context, supplier propagation.HTTPSupplie supportedVersion, sc.TraceID, sc.SpanID, - sc.TraceFlags&TraceFlagsSampled) + sc.TraceFlags&FlagsSampled) supplier.Set(traceparentHeader, h) } @@ -137,7 +137,7 @@ func (TraceContext) extract(supplier propagation.HTTPSupplier) SpanContext { if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) { return EmptySpanContext() } - sc.TraceFlags = opts[0] &^ TraceFlagsUnused + sc.TraceFlags = opts[0] &^ FlagsUnused if !sc.IsValid() { return EmptySpanContext() diff --git a/internal/trace/mock_tracer.go b/internal/trace/mock_tracer.go index 4498434e8..6c58dff01 100644 --- a/internal/trace/mock_tracer.go +++ b/internal/trace/mock_tracer.go @@ -69,7 +69,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Star sc = apitrace.SpanContext{} _, _ = rand.Read(sc.TraceID[:]) if mt.Sampled { - sc.TraceFlags = apitrace.TraceFlagsSampled + sc.TraceFlags = apitrace.FlagsSampled } } else { sc = parentSpanContext diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 6e0a8f540..ff89c4517 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -29,7 +29,7 @@ func TestAlwaysParentSampleWithParentSampled(t *testing.T) { parentCtx := trace.SpanContext{ TraceID: traceID, SpanID: spanID, - TraceFlags: trace.TraceFlagsSampled, + TraceFlags: trace.FlagsSampled, } if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled { t.Error("Sampling decision should be RecordAndSampled") diff --git a/sdk/trace/span.go b/sdk/trace/span.go index dc24d3c21..9753968d2 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -403,13 +403,13 @@ func makeSamplingDecision(data samplingData) SamplingResult { Links: data.links, }) if sampled.Decision == RecordAndSampled { - spanContext.TraceFlags |= apitrace.TraceFlagsSampled + spanContext.TraceFlags |= apitrace.FlagsSampled } else { - spanContext.TraceFlags &^= apitrace.TraceFlagsSampled + spanContext.TraceFlags &^= apitrace.FlagsSampled } return sampled } - if data.parent.TraceFlags&apitrace.TraceFlagsSampled != 0 { + if data.parent.TraceFlags&apitrace.FlagsSampled != 0 { return SamplingResult{Decision: RecordAndSampled} } return SamplingResult{Decision: NotRecord} diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 137e85f22..c96d6bce7 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -200,7 +200,7 @@ func TestSampling(t *testing.T) { SpanID: idg.NewSpanID(), } if tc.sampledParent { - psc.TraceFlags = apitrace.TraceFlagsSampled + psc.TraceFlags = apitrace.FlagsSampled } ctx = apitrace.ContextWithRemoteSpanContext(ctx, psc) }