func debugFromContext(ctx context.Context) bool {
	if ctx == nil {
		return false
	}
	if debug, ok := ctx.Value(debugKey).(bool); ok {
		return debug
	}
	return false
}
debugFromContext returns the debug value stored in ctx.

If no debug value is stored in ctx false is returned.
package propagation
import (
	"context"
	"errors"
	"strings"
)
const (
	b3ContextHeader      = "b3"
	b3DebugFlagHeader    = "x-b3-flags"
	b3TraceIDHeader      = "x-b3-traceid"
	b3SpanIDHeader       = "x-b3-spanid"
	b3SampledHeader      = "x-b3-sampled"
	b3ParentSpanIDHeader = "x-b3-parentspanid"
	b3TraceIDPadding = "0000000000000000"
	separatorWidth      = 1        
	samplingWidth       = 1        
	traceID64BitsWidth  = 64 / 4   
	traceID128BitsWidth = 128 / 4  
	spanIDWidth         = 16       
	parentSpanIDWidth   = 16       
)
var (
	empty = PropagationContext{}
	errInvalidSampledByte        = errors.New("invalid B3 Sampled found")
	errInvalidSampledHeader      = errors.New("invalid B3 Sampled header found")
	errInvalidTraceIDHeader      = errors.New("invalid B3 traceID header found")
	errInvalidSpanIDHeader       = errors.New("invalid B3 spanID header found")
	errInvalidParentSpanIDHeader = errors.New("invalid B3 ParentSpanID header found")
	errInvalidScope              = errors.New("require either both traceID and spanID or none")
	errInvalidScopeParent        = errors.New("ParentSpanID requires both traceID and spanID to be available")
	errInvalidScopeParentSingle  = errors.New("ParentSpanID requires traceID, spanID and Sampled to be available")
	errEmptyContext              = errors.New("empty request context")
	errInvalidTraceIDValue       = errors.New("invalid B3 traceID value found")
	errInvalidSpanIDValue        = errors.New("invalid B3 spanID value found")
	errInvalidParentSpanIDValue  = errors.New("invalid B3 ParentSpanID value found")
)
func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled, flags string) (context.Context, PropagationContext, error) {
	var (
		err           error
		requiredCount int
		prop          = PropagationContext{}
	)
	switch strings.ToLower(sampled) {
	case "0", "false":
	case "1", "true":
		prop.TraceFlags = FlagsSampled
	case "":
		ctx = withDeferred(ctx, true)
	default:
		return ctx, empty, errInvalidSampledHeader
	}
	if flags == "1" {
		ctx = withDeferred(ctx, false)
		ctx = withDebug(ctx, true)
		prop.TraceFlags |= FlagsSampled
	}
	if traceID != "" {
		requiredCount++
		id := traceID
		if len(traceID) == 16 {
			id = b3TraceIDPadding + traceID
		}
		tID, err := traceIDFromHex(id)
		if err != nil {
			return ctx, empty, errInvalidTraceIDHeader
		}
		prop.TraceID = tID.String()
	}
	if spanID != "" {
		requiredCount++
		sID, err := spanIDFromHex(spanID)
		if err != nil {
			return ctx, empty, errInvalidSpanIDHeader
		}
		prop.ParentID = sID.String()
	}
	if requiredCount != 0 && requiredCount != 2 {
		return ctx, empty, errInvalidScope
	}
	if parentSpanID != "" {
		if requiredCount == 0 {
			return ctx, empty, errInvalidScopeParent
		}
		if _, err = spanIDFromHex(parentSpanID); err != nil {
			return ctx, empty, errInvalidParentSpanIDHeader
		}
	}
	return ctx, prop, nil
}
func extractSingle(ctx context.Context, contextHeader string) (context.Context, PropagationContext, error) {
	if contextHeader == "" {
		return ctx, empty, errEmptyContext
	}
	var (
		prop     = PropagationContext{}
		sampling string
	)
	headerLen := len(contextHeader)
	if headerLen == samplingWidth {
		sampling = contextHeader
	} else if headerLen == traceID64BitsWidth || headerLen == traceID128BitsWidth {
		return ctx, empty, errInvalidScope
	} else if headerLen >= traceID64BitsWidth+spanIDWidth+separatorWidth {
		pos := 0
		var traceID string
		if string(contextHeader[traceID64BitsWidth]) == "-" {
			pos += traceID64BitsWidth  
			traceID = b3TraceIDPadding + string(contextHeader[0:pos])
		} else if string(contextHeader[32]) == "-" {
			pos += traceID128BitsWidth  
			traceID = string(contextHeader[0:pos])
		} else {
			return ctx, empty, errInvalidTraceIDValue
		}
		var err error
		tID, err := traceIDFromHex(traceID)
		if err != nil {
			return ctx, empty, errInvalidTraceIDValue
		}
		prop.TraceID = tID.String()
		pos += separatorWidth  
		spanID, err := spanIDFromHex(contextHeader[pos : pos+spanIDWidth])
		if err != nil {
			return ctx, empty, errInvalidSpanIDValue
		}
		prop.ParentID = spanID.String()
		pos += spanIDWidth  
		if headerLen > pos {
			if headerLen == pos+separatorWidth {
				return ctx, empty, errInvalidSampledByte
			}
			pos += separatorWidth  
			if headerLen == pos+samplingWidth {
				sampling = string(contextHeader[pos])
			} else if headerLen == pos+parentSpanIDWidth {
				return ctx, empty, errInvalidScopeParentSingle
			} else if headerLen == pos+samplingWidth+separatorWidth+parentSpanIDWidth {
				sampling = string(contextHeader[pos])
				pos += samplingWidth + separatorWidth  
				_, err = spanIDFromHex(contextHeader[pos:])
				if err != nil {
					return ctx, empty, errInvalidParentSpanIDValue
				}
			} else {
				return ctx, empty, errInvalidParentSpanIDValue
			}
		}
	} else {
		return ctx, empty, errInvalidTraceIDValue
	}
	switch sampling {
	case "":
		ctx = withDeferred(ctx, true)
	case "d":
		ctx = withDebug(ctx, true)
		prop.TraceFlags = FlagsSampled
	case "1":
		prop.TraceFlags = FlagsSampled
	case "0":
	default:
		return ctx, empty, errInvalidSampledByte
	}
	return ctx, prop, nil
}
type b3KeyType int
const (
	debugKey b3KeyType = iota
	deferredKey
)
func withDebug(parent context.Context, debug bool) context.Context {
	return context.WithValue(parent, debugKey, debug)
}
func deferredFromContext(ctx context.Context) bool {
	if ctx == nil {
		return false
	}
	if deferred, ok := ctx.Value(deferredKey).(bool); ok {
		return deferred
	}
	return false
}
func withDeferred(parent context.Context, deferred bool) context.Context {
	return context.WithValue(parent, deferredKey, deferred)
}