Debian Codegraph @

pdata/pcommon/traceid.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pcommon // import "go.opentelemetry.io/collector/pdata/pcommon"
5
6 import (
7 "encoding/hex"
8
9 "go.opentelemetry.io/collector/pdata/internal"
10 )
11
12 var emptyTraceID = TraceID([16]byte{})
13
14 // TraceID is a trace identifier.
15 type TraceID [16]byte
16
17 // NewTraceIDEmpty returns a new empty (all zero bytes) TraceID.
18 func NewTraceIDEmpty() TraceID {
19 return emptyTraceID
20 }
21
22 // String returns string representation of the TraceID.
23 //
24 // Important: Don't rely on this method to get a string identifier of TraceID.
25 // Use hex.EncodeToString explicitly instead.
26 // This method meant to implement Stringer interface for display purposes only.
27 func (ms TraceID) String() string {
28 if ms.IsEmpty() {
29 return ""
30 }
31 return hex.EncodeToString(ms[:])
32 }
33
34 // IsEmpty returns true if id doesn't contain at least one non-zero byte.
35 func (ms TraceID) IsEmpty() bool {
36 return internal.TraceID(ms).IsEmpty()
37 }