Source File
ids.go
Belonging Package
go.pact.im/x/traces
package tracesimport (crand)// TraceID is a 16-byte W3C trace identifier.type TraceID [16]byte// SpanID is an 8-byte W3C span identifier.type SpanID [8]byte// IsValid reports whether id is non-zero.func ( TraceID) () bool {return != TraceID{}}// IsValid reports whether id is non-zero.func ( SpanID) () bool {return != SpanID{}}// String returns the 32-character lowercase hex encoding of id.func ( TraceID) () string {return hex.EncodeToString([:])}// String returns the 16-character lowercase hex encoding of id.func ( SpanID) () string {return hex.EncodeToString([:])}// IDSource generates trace and span identifiers for a [Tracer].// Implementations must be safe for concurrent use and must return valid// (non-zero) identifiers.type IDSource interface {// NewTraceID returns a new valid [TraceID].NewTraceID() TraceID// NewSpanID returns a new valid [SpanID].NewSpanID() SpanID}// RandomIDs returns an [IDSource] backed by a ChaCha8 generator seeded from// [crypto/rand]. It is safe for concurrent use.func () IDSource {var [32]byte_, _ = crand.Read([:])return &randomIDs{rng: rand.NewChaCha8()}}type randomIDs struct {mu sync.Mutexrng *rand.ChaCha8}func ( *randomIDs) () ( TraceID) {for !.IsValid() {.mu.Lock()binary.LittleEndian.PutUint64([:8], .rng.Uint64())binary.LittleEndian.PutUint64([8:], .rng.Uint64()).mu.Unlock()}return}func ( *randomIDs) () ( SpanID) {for !.IsValid() {.mu.Lock()binary.LittleEndian.PutUint64([:], .rng.Uint64()).mu.Unlock()}return}
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)