github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tracer/exptel/span_context.go (about) 1 package exptel 2 3 import ( 4 "encoding/hex" 5 "encoding/json" 6 7 "go.opentelemetry.io/otel/trace" 8 ) 9 10 // SpanContext contains basic information about the span - its trace 11 // ID, span ID and trace flags. 12 type SpanContext struct { 13 TraceID TraceID 14 SpanID SpanID 15 TraceFlags byte 16 } 17 18 func NewSpanContextFromOtel(c trace.SpanContext) SpanContext { 19 return SpanContext{ 20 TraceID: TraceID(c.TraceID()), 21 SpanID: SpanID(c.SpanID()), 22 TraceFlags: byte(c.TraceFlags()), 23 } 24 } 25 26 // TraceID is a unique identity of a trace. 27 type TraceID [16]byte 28 29 // MarshalJSON implements a custom marshal function to encode TraceID 30 // as a hex string. 31 func (t TraceID) MarshalJSON() ([]byte, error) { 32 return json.Marshal(hex.EncodeToString(t[:])) 33 } 34 35 // SpanID is a unique identify of a span in a trace. 36 type SpanID [8]byte 37 38 // MarshalJSON implements a custom marshal function to encode SpanID 39 // as a hex string. 40 func (s SpanID) MarshalJSON() ([]byte, error) { 41 return json.Marshal(hex.EncodeToString(s[:])) 42 }