-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
65 lines (54 loc) · 1.18 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
package ssormotel
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
)
const (
name = "github.com/10antz-inc/ssorm/ssormotel"
)
type config struct {
tp trace.TracerProvider
tracer trace.Tracer
attrs []attribute.KeyValue
enableQueryStatement bool
statement string
}
type Option interface {
apply(conf *config)
}
type option func(conf *config)
func (fn option) apply(conf *config) {
fn(conf)
}
func newConfig(opts ...Option) *config {
tp := otel.GetTracerProvider()
conf := &config{
tp: tp,
tracer: tp.Tracer(name),
attrs: []attribute.KeyValue{
semconv.DBSystemKey.String("spanner"),
},
enableQueryStatement: false,
}
for _, opt := range opts {
opt.apply(conf)
}
return conf
}
func WithAttributes(attrs ...attribute.KeyValue) Option {
return option(func(conf *config) {
conf.attrs = append(conf.attrs, attrs...)
})
}
func WithTracerProvider(provider trace.TracerProvider) Option {
return option(func(conf *config) {
conf.tp = provider
})
}
func WithQueryStatement() Option {
return option(func(conf *config) {
conf.enableQueryStatement = true
})
}