/
option.go
42 lines (35 loc) · 989 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
38
39
40
41
42
package memcache
const (
serviceName = "memcached"
operationName = "memcached.query"
)
type clientConfig struct {
serviceName string
analyticsRate float64
}
// ClientOption represents an option that can be passed to Dial.
type ClientOption func(*clientConfig)
func defaults(cfg *clientConfig) {
cfg.serviceName = serviceName
// cfg.analyticsRate = globalconfig.AnalyticsRate()
}
// WithServiceName sets the given service name for the dialled connection.
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
}
}