util

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTraceNotFound can be used when we don't find a trace
	ErrTraceNotFound = errors.New("trace not found")

	// StatusClientClosedRequest is the status code for when a client request cancellation of an http request
	StatusClientClosedRequest     = 499
	StatusTextClientClosedRequest = "Request Cancelled"

	ErrUnsupported = fmt.Errorf("unsupported")
)

Functions

func EqualHexStringTraceIDs

func EqualHexStringTraceIDs(a, b string) (bool, error)

EqualHexStringTraceIDs compares two trace ID strings and compares the resulting bytes after padding. Returns true unless there is a reason not to.

func HexStringToSpanID

func HexStringToSpanID(id string) ([]byte, error)

func HexStringToTraceID

func HexStringToTraceID(id string) ([]byte, error)

func NewTokenHasher

func NewTokenHasher() hash.Hash64

NewTokenHasher returns a new hash.Hash64 for use with TokenForID.

func PadTraceIDString

func PadTraceIDString(id string) string

PadTraceIDString left-pads a trace ID hex string to 32 characters with zeros. This produces W3C/OpenTelemetry compliant 32-character lowercase hex trace IDs.

func PadTraceIDTo16Bytes

func PadTraceIDTo16Bytes(traceID []byte) []byte

func SpanIDAndKindToToken

func SpanIDAndKindToToken(id []byte, kind int) uint64

SpanIDAndKindToToken converts a span ID into a token for use as key in a hash map. The token is generated such that it has a low collision probability. In zipkin traces the span id is not guaranteed to be unique as it is shared between client and server spans. Therefore, it is sometimes required to take the span kind into account.

func SpanIDToHexString

func SpanIDToHexString(byteID []byte) string

SpanIDToHexString converts a span ID to its string representation and WITHOUT removing any leading zeros. If the id is < 16, left pad with 0s

func SpanIDToUint64

func SpanIDToUint64(id []byte) uint64

SpanIDToUint64 converts a span ID into an uint64 representation. This is useful when using a span ID as key in a map. If the ID is longer than 8 bytes, the bytes at larger positions are discarded. The function does not make any guarantees about the endianess or ordering of converted IDs.

Note: span IDs are not always unique within a trace (e.g. zipkin traces) SpanIDAndKindToToken could be more appropriate in some cases.

func StatusText

func StatusText(code int) string

func TokenForID

func TokenForID(h hash.Hash64, buffer []byte, kind int32, id []byte) uint64

TokenForID returns a token for use as a key in a hash map given a span ID and span kind. h and buffer (must be at least 4 bytes) are provided by the caller for reuse across calls to avoid repeated allocations. Use NewTokenHasher to create h. kind is included because in zipkin traces the span id is shared between client and server spans.

func TraceIDToHexString

func TraceIDToHexString(byteID []byte) string

TraceIDToHexString converts a trace ID to its string representation and removes any leading zeros.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL