forked from chengjiagan/twirp-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
66 lines (57 loc) · 1.57 KB
/
config.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
62
63
64
65
66
package oteltwirp
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
// config is a group of options for this instrumentation.
type config struct {
propagator propagation.TextMapPropagator
tracerProvider trace.TracerProvider
includeClientErrors bool
}
// Option applies an option value for a config.
type Option interface {
apply(*config)
}
type optionFunc func(*config)
func (o optionFunc) apply(c *config) {
o(c)
}
// newConfig returns a config configured with all the passed Options.
func newConfig(opts []Option) *config {
c := &config{
propagator: otel.GetTextMapPropagator(),
tracerProvider: otel.GetTracerProvider(),
includeClientErrors: true,
}
for _, o := range opts {
o.apply(c)
}
return c
}
// WithPropagators returns an Option to use the Propagators when extracting
// and injecting trace context from requests.
func WithPropagators(p propagation.TextMapPropagator) Option {
return optionFunc(func(c *config) {
if p != nil {
c.propagator = p
}
})
}
// WithTracerProvider returns an Option to use the TracerProvider when
// creating a Tracer.
func WithTracerProvider(tp trace.TracerProvider) Option {
return optionFunc(func(c *config) {
if tp != nil {
c.tracerProvider = tp
}
})
}
// IncludeClientErrors, if set, will report client errors (4xx) as errors in the server span.
// If not set, only 5xx status will be reported as erroneous.
func IncludeClientErrors(include bool) Option {
return optionFunc(func(c *config) {
c.includeClientErrors = include
})
}