-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwfoption.go
61 lines (47 loc) · 1.65 KB
/
wfoption.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
53
54
55
56
57
58
59
60
61
package zkafka
import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
// WorkFactoryOption interface to identify functional options
type WorkFactoryOption interface {
apply(s *WorkFactory)
}
// WithLogger provides option to override the logger to use. default is noop
func WithLogger(l Logger) WorkFactoryOption { return loggerOption{l} }
// WithTracerProvider provides option to specify the otel tracer provider used by the created work object.
// Defaults to nil (which means no tracing)
func WithTracerProvider(tp trace.TracerProvider) WorkFactoryOption {
return tracerProviderOption{tp: tp}
}
// WithTextMapPropagator provides option to specify the otel text map propagator used by the created work object.
// Defaults to nil (which means no propagation of transport across transports)
func WithTextMapPropagator(p propagation.TextMapPropagator) WorkFactoryOption {
return wfPropagatorsOption{p}
}
// WithWorkLifecycleHooks provides option to override the lifecycle hooks. Default is noop.
func WithWorkLifecycleHooks(h LifecycleHooks) WorkFactoryOption {
return LifecycleHooksOption{h}
}
type loggerOption struct{ l Logger }
func (s loggerOption) apply(wf *WorkFactory) {
if s.l != nil {
wf.logger = s.l
}
}
type tracerProviderOption struct{ tp trace.TracerProvider }
func (s tracerProviderOption) apply(wf *WorkFactory) {
if s.tp != nil {
wf.tp = s.tp
}
}
type wfPropagatorsOption struct {
p propagation.TextMapPropagator
}
func (s wfPropagatorsOption) apply(wf *WorkFactory) {
wf.p = s.p
}
type LifecycleHooksOption struct{ h LifecycleHooks }
func (h LifecycleHooksOption) apply(wf *WorkFactory) {
wf.lifecycle = h.h
}