go.undefinedlabs.com/scopeagent@v0.4.2/tracer/wire/carrier.go (about)

     1  package wire
     2  
     3  // ProtobufCarrier is a DelegatingCarrier that uses protocol buffers as the
     4  // the underlying datastructure. The reason for implementing DelagatingCarrier
     5  // is to allow for end users to serialize the underlying protocol buffers using
     6  // jsonpb or any other serialization forms they want.
     7  type ProtobufCarrier TracerState
     8  
     9  // SetState set's the tracer state.
    10  func (p *ProtobufCarrier) SetState(traceIDHi, traceIDLo, spanID uint64, sampled bool) {
    11  	p.TraceIdHi = traceIDHi
    12  	p.TraceIdLo = traceIDLo
    13  	p.SpanId = spanID
    14  	p.Sampled = sampled
    15  }
    16  
    17  // State returns the tracer state.
    18  func (p *ProtobufCarrier) State() (traceIDHi, traceIDLo, spanID uint64, sampled bool) {
    19  	traceIDHi = p.TraceIdHi
    20  	traceIDLo = p.TraceIdLo
    21  	spanID = p.SpanId
    22  	sampled = p.Sampled
    23  	return traceIDHi, traceIDLo, spanID, sampled
    24  }
    25  
    26  // SetBaggageItem sets a baggage item.
    27  func (p *ProtobufCarrier) SetBaggageItem(key, value string) {
    28  	if p.BaggageItems == nil {
    29  		p.BaggageItems = map[string]string{key: value}
    30  		return
    31  	}
    32  
    33  	p.BaggageItems[key] = value
    34  }
    35  
    36  // GetBaggage iterates over each baggage item and executes the callback with
    37  // the key:value pair.
    38  func (p *ProtobufCarrier) GetBaggage(f func(k, v string)) {
    39  	for k, v := range p.BaggageItems {
    40  		f(k, v)
    41  	}
    42  }