forked from DataDog/dd-trace-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
38 lines (32 loc) · 1020 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
package grpc
type interceptorConfig struct {
serviceName string
analyticsRate float64
}
// InterceptorOption represents an option that can be passed to the grpc unary
// client and server interceptors.
type InterceptorOption func(*interceptorConfig)
func defaults(cfg *interceptorConfig) {
// cfg.serviceName default set in interceptor
// cfg.analyticsRate = globalconfig.AnalyticsRate()
}
// WithServiceName sets the given service name for the intercepted client.
func WithServiceName(name string) InterceptorOption {
return func(cfg *interceptorConfig) {
cfg.serviceName = name
}
}
// WithAnalytics enables Trace Analytics for all started spans.
func WithAnalytics(on bool) InterceptorOption {
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) InterceptorOption {
return func(cfg *interceptorConfig) {
cfg.analyticsRate = rate
}
}