123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package propagation
- import (
- "net/http"
- "go.opencensus.io/trace"
- )
- func Binary(sc trace.SpanContext) []byte {
- if sc == (trace.SpanContext{}) {
- return nil
- }
- var b [29]byte
- copy(b[2:18], sc.TraceID[:])
- b[18] = 1
- copy(b[19:27], sc.SpanID[:])
- b[27] = 2
- b[28] = uint8(sc.TraceOptions)
- return b[:]
- }
- func FromBinary(b []byte) (sc trace.SpanContext, ok bool) {
- if len(b) == 0 || b[0] != 0 {
- return trace.SpanContext{}, false
- }
- b = b[1:]
- if len(b) >= 17 && b[0] == 0 {
- copy(sc.TraceID[:], b[1:17])
- b = b[17:]
- } else {
- return trace.SpanContext{}, false
- }
- if len(b) >= 9 && b[0] == 1 {
- copy(sc.SpanID[:], b[1:9])
- b = b[9:]
- }
- if len(b) >= 2 && b[0] == 2 {
- sc.TraceOptions = trace.TraceOptions(b[1])
- }
- return sc, true
- }
- type HTTPFormat interface {
- SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool)
- SpanContextToRequest(sc trace.SpanContext, req *http.Request)
- }
|