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