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()