forked from DataDog/dd-trace-go
/
option.go
48 lines (40 loc) · 1.04 KB
/
option.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
package buntdb
import "context"
type config struct {
ctx context.Context
serviceName string
analyticsRate float64
}
func defaults(cfg *config) {
cfg.serviceName = "buntdb"
cfg.ctx = context.Background()
// cfg.analyticsRate = globalconfig.AnalyticsRate()
}
// An Option customizes the config.
type Option func(cfg *config)
// WithContext sets the context for the transaction.
func WithContext(ctx context.Context) Option {
return func(cfg *config) {
cfg.ctx = ctx
}
}
// WithServiceName sets the given service name for the transaction.
func WithServiceName(serviceName string) Option {
return func(cfg *config) {
cfg.serviceName = serviceName
}
}
// WithAnalytics enables Trace Analytics for all started spans.
func WithAnalytics(on bool) Option {
if on {
return WithAnalyticsRate(1.0)
}
return WithAnalyticsRate(0.0)
}
// WithAnalyticsRate sets the sampling rate for Trace Analytics events
// correlated to started spans.
func WithAnalyticsRate(rate float64) Option {
return func(cfg *config) {
cfg.analyticsRate = rate
}
}