1package lightstep 2 3import ( 4 "time" 5 6 "github.com/opentracing/opentracing-go" 7) 8 9// RawSpan encapsulates all state associated with a (finished) LightStep Span. 10type RawSpan struct { 11 // Those recording the RawSpan should also record the contents of its 12 // SpanContext. 13 Context SpanContext 14 15 // The SpanID of this SpanContext's first intra-trace reference (i.e., 16 // "parent"), or 0 if there is no parent. 17 ParentSpanID uint64 18 19 // The name of the "operation" this span is an instance of. (Called a "span 20 // name" in some implementations) 21 Operation string 22 23 // We store <start, duration> rather than <start, end> so that only 24 // one of the timestamps has global clock uncertainty issues. 25 Start time.Time 26 Duration time.Duration 27 28 // Essentially an extension mechanism. Can be used for many purposes, 29 // not to be enumerated here. 30 Tags opentracing.Tags 31 32 // The span's "microlog". 33 Logs []opentracing.LogRecord 34} 35 36// SpanContext holds lightstep-specific Span metadata. 37type SpanContext struct { 38 // A probabilistically unique identifier for a [multi-span] trace. 39 TraceID uint64 40 41 // Most significant bits of a 128-bit TraceID 42 TraceIDUpper uint64 43 44 // A probabilistically unique identifier for a span. 45 SpanID uint64 46 47 // Propagates sampling decision 48 Sampled string 49 50 // The span's associated baggage. 51 Baggage map[string]string // initialized on first use 52} 53 54// ForeachBaggageItem belongs to the opentracing.SpanContext interface 55func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool) { 56 for k, v := range c.Baggage { 57 if !handler(k, v) { 58 break 59 } 60 } 61} 62 63// WithBaggageItem returns an entirely new basictracer SpanContext with the 64// given key:value baggage pair set. 65func (c SpanContext) WithBaggageItem(key, val string) SpanContext { 66 var newBaggage map[string]string 67 if c.Baggage == nil { 68 newBaggage = map[string]string{key: val} 69 } else { 70 newBaggage = make(map[string]string, len(c.Baggage)+1) 71 for k, v := range c.Baggage { 72 newBaggage[k] = v 73 } 74 newBaggage[key] = val 75 } 76 // Use positional parameters so the compiler will help catch new fields. 77 78 return SpanContext{c.TraceID, c.TraceIDUpper, c.SpanID, c.Sampled, newBaggage} 79} 80