@@ -10,6 +10,7 @@ import (
10
10
// DataDogClient is a dogstatsd metrics client implementation.
11
11
type DataDogClient struct {
12
12
client * statsd.Client
13
+ rate float64
13
14
tagMap map [string ]string
14
15
}
15
16
@@ -29,6 +30,16 @@ func NewDataDogClient(address string, namespace string) *DataDogClient {
29
30
30
31
return & DataDogClient {
31
32
client : c ,
33
+ rate : 1.0 ,
34
+ }
35
+ }
36
+
37
+ // WithRate clones this client with a new sample rate.
38
+ func (c * DataDogClient ) WithRate (rate float64 ) Client {
39
+ return & DataDogClient {
40
+ client : c .client ,
41
+ rate : rate ,
42
+ tagMap : combine (c .tagMap , map [string ]string {}),
32
43
}
33
44
}
34
45
@@ -37,6 +48,7 @@ func NewDataDogClient(address string, namespace string) *DataDogClient {
37
48
func (c * DataDogClient ) WithTags (tags map [string ]string ) Client {
38
49
return & DataDogClient {
39
50
client : c .client ,
51
+ rate : c .rate ,
40
52
tagMap : combine (c .tagMap , tags ),
41
53
}
42
54
}
@@ -47,7 +59,7 @@ func (c *DataDogClient) tagsList() []string {
47
59
48
60
// Count adds some integer value to a metric.
49
61
func (c * DataDogClient ) Count (name string , value int64 ) {
50
- c .client .Count (name , value , c .tagsList (), 1.0 )
62
+ c .client .Count (name , value , c .tagsList (), c . rate )
51
63
}
52
64
53
65
// Incr adds one to a metric.
@@ -62,7 +74,7 @@ func (c *DataDogClient) Decr(name string) {
62
74
63
75
// Gauge sets a numeric value.
64
76
func (c * DataDogClient ) Gauge (name string , value float64 ) {
65
- c .client .Gauge (name , value , c .tagsList (), 1.0 )
77
+ c .client .Gauge (name , value , c .tagsList (), c . rate )
66
78
}
67
79
68
80
// Event tracks an event that may be relevant to other metrics.
@@ -76,10 +88,10 @@ func (c *DataDogClient) Event(e *statsd.Event) {
76
88
77
89
// Timing tracks a duration.
78
90
func (c * DataDogClient ) Timing (name string , value time.Duration ) {
79
- c .client .Timing (name , value , c .tagsList (), 1 )
91
+ c .client .Timing (name , value , c .tagsList (), c . rate )
80
92
}
81
93
82
94
// Histogram sets a numeric value while tracking min/max/avg/p95/etc.
83
95
func (c * DataDogClient ) Histogram (name string , value float64 ) {
84
- c .client .Histogram (name , value , c .tagsList (), 1.0 )
96
+ c .client .Histogram (name , value , c .tagsList (), c . rate )
85
97
}
0 commit comments