-
Notifications
You must be signed in to change notification settings - Fork 53
/
propagation_stack.go
52 lines (44 loc) · 1.32 KB
/
propagation_stack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package lightstep
import (
"errors"
"github.com/opentracing/opentracing-go"
)
// PropagatorStack provides a Propagator interface that supports
// multiple propagators per format.
type PropagatorStack struct {
propagators []Propagator
}
// PushPropagator adds a Propagator to a list of configured propagators
func (stack *PropagatorStack) PushPropagator(p Propagator) {
stack.propagators = append(stack.propagators, p)
}
// Inject iterates through configured propagators and calls
// their Inject functions
func (stack PropagatorStack) Inject(
spanContext opentracing.SpanContext,
opaqueCarrier interface{},
) error {
if len(stack.propagators) == 0 {
return errors.New("No valid propagator configured")
}
for _, propagator := range stack.propagators {
propagator.Inject(spanContext, opaqueCarrier)
}
return nil
}
// Extract iterates through configured propagators and
// returns the first successfully extracted context
func (stack PropagatorStack) Extract(
opaqueCarrier interface{},
) (opentracing.SpanContext, error) {
if len(stack.propagators) == 0 {
return nil, errors.New("No valid propagator configured")
}
for _, propagator := range stack.propagators {
context, err := propagator.Extract(opaqueCarrier)
if err == nil {
return context, nil
}
}
return nil, errors.New("No valid propagator configured")
}