| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package b3 // import "go.opentelemetry.io/contrib/propagators/b3" |
| 5 |
|
| 6 |
import "context" |
| 7 |
|
| 8 |
type b3KeyType int |
| 9 |
|
| 10 |
const ( |
| 11 |
debugKey b3KeyType = iota |
| 12 |
deferredKey |
| 13 |
) |
| 14 |
|
| 15 |
// withDebug returns a copy of parent with debug set as the debug flag value . |
| 16 |
func withDebug(parent context.Context, debug bool) context.Context { |
| 17 |
return context.WithValue(parent, debugKey, debug) |
| 18 |
} |
| 19 |
|
| 20 |
// debugFromContext returns the debug value stored in ctx. |
| 21 |
// |
| 22 |
// If no debug value is stored in ctx false is returned. |
| 23 |
func debugFromContext(ctx context.Context) bool { |
| 24 |
if ctx == nil { |
| 25 |
return false |
| 26 |
} |
| 27 |
if debug, ok := ctx.Value(debugKey).(bool); ok { |
| 28 |
return debug |
| 29 |
} |
| 30 |
return false |
| 31 |
} |
| 32 |
|
| 33 |
// withDeferred returns a copy of parent with deferred set as the deferred flag value . |
| 34 |
func withDeferred(parent context.Context, deferred bool) context.Context { |
| 35 |
return context.WithValue(parent, deferredKey, deferred) |
| 36 |
} |
| 37 |
|
| 38 |
// deferredFromContext returns the deferred value stored in ctx. |
| 39 |
// |
| 40 |
// If no deferred value is stored in ctx false is returned. |
| 41 |
func deferredFromContext(ctx context.Context) bool { |
| 42 |
if ctx == nil { |
| 43 |
return false |
| 44 |
} |
| 45 |
if deferred, ok := ctx.Value(deferredKey).(bool); ok { |
| 46 |
return deferred |
| 47 |
} |
| 48 |
return false |
| 49 |
} |