go.undefinedlabs.com/scopeagent@v0.4.2/tracer/context.go (about) 1 package tracer 2 3 import "github.com/google/uuid" 4 5 // SpanContext holds the basic Span metadata. 6 type SpanContext struct { 7 // A probabilistically unique identifier for a [multi-span] trace. 8 TraceID uuid.UUID 9 10 // A probabilistically unique identifier for a span. 11 SpanID uint64 12 13 // Whether the trace is sampled. 14 Sampled bool 15 16 // The span's associated baggage. 17 Baggage map[string]string // initialized on first use 18 } 19 20 // ForeachBaggageItem belongs to the opentracing.SpanContext interface 21 func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool) { 22 for k, v := range c.Baggage { 23 if !handler(k, v) { 24 break 25 } 26 } 27 } 28 29 // WithBaggageItem returns an entirely new basictracer SpanContext with the 30 // given key:value baggage pair set. 31 func (c SpanContext) WithBaggageItem(key, val string) SpanContext { 32 var newBaggage map[string]string 33 if c.Baggage == nil { 34 newBaggage = map[string]string{key: val} 35 } else { 36 newBaggage = make(map[string]string, len(c.Baggage)+1) 37 for k, v := range c.Baggage { 38 newBaggage[k] = v 39 } 40 newBaggage[key] = val 41 } 42 // Use positional parameters so the compiler will help catch new fields. 43 return SpanContext{c.TraceID, c.SpanID, c.Sampled, newBaggage} 44 }