1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
19 func (t TraceID) String() string {
20 return fmt.Sprintf("%02x", t[:])
23 func (s SpanID) String() string {
24 return fmt.Sprintf("%02x", s[:])
27 func (s SpanID) IsValid() bool {
32 generationMu sync.Mutex
37 traceIDRand *rand.Rand
40 func initGenerator() {
42 for _, p := range []interface{}{
43 &rngSeed, &traceIDAdd, &nextSpanID, &spanIDInc,
45 binary.Read(crand.Reader, binary.LittleEndian, p)
47 traceIDRand = rand.New(rand.NewSource(rngSeed))
51 func newTraceID() TraceID {
53 defer generationMu.Unlock()
54 if traceIDRand == nil {
58 binary.LittleEndian.PutUint64(tid[0:8], traceIDRand.Uint64()+traceIDAdd[0])
59 binary.LittleEndian.PutUint64(tid[8:16], traceIDRand.Uint64()+traceIDAdd[1])
63 func newSpanID() SpanID {
66 id = atomic.AddUint64(&nextSpanID, spanIDInc)
69 binary.LittleEndian.PutUint64(sid[:], id)