forked from DataDog/dd-trace-go
/
option.go
37 lines (31 loc) · 986 Bytes
/
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
package redis // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis"
type clientConfig struct {
serviceName string
analyticsRate float64
}
// ClientOption represents an option that can be used to create or wrap a client.
type ClientOption func(*clientConfig)
func defaults(cfg *clientConfig) {
cfg.serviceName = "redis.client"
// cfg.analyticsRate = globalconfig.AnalyticsRate()
}
// WithServiceName sets the given service name for the client.
func WithServiceName(name string) ClientOption {
return func(cfg *clientConfig) {
cfg.serviceName = name
}
}
// WithAnalytics enables Trace Analytics for all started spans.
func WithAnalytics(on bool) ClientOption {
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) ClientOption {
return func(cfg *clientConfig) {
cfg.analyticsRate = rate
}
}