1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-13 01:00:22 +02:00

Rename trace.TraceID & trace.TraceIDFromHex

This commit is contained in:
tensorchen
2020-05-02 20:23:09 +08:00
parent c6c155de6f
commit bae2298a36
31 changed files with 88 additions and 88 deletions

View File

@ -32,7 +32,7 @@ type alwaysOffSampler struct{}
func (ns alwaysOffSampler) ShouldSample(
_ SpanContext,
_ bool,
_ TraceID,
_ ID,
_ SpanID,
_ string,
_ SpanKind,

View File

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

View File

@ -32,7 +32,7 @@ type alwaysOnSampler struct{}
func (as alwaysOnSampler) ShouldSample(
_ SpanContext,
_ bool,
_ TraceID,
_ ID,
_ SpanID,
_ string,
_ SpanKind,

View File

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

View File

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

View File

@ -23,7 +23,7 @@ type Sampler interface {
ShouldSample(
sc SpanContext,
remote bool,
traceID TraceID,
traceID ID,
spanID SpanID,
spanName string,
spanKind SpanKind,

View File

@ -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
}

View File

@ -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",
},
} {

View File

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

View File

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

View File

@ -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,

View File

@ -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
}

View File

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

View File

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

View File

@ -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

View File

@ -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}
}

View File

@ -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,
},

View File

@ -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),
},

View File

@ -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"

View File

@ -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

View File

@ -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},

View File

@ -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:]),

View File

@ -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},

View File

@ -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,

View File

@ -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"

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

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