@@ -11,7 +11,7 @@ import (
11
11
type DataDogClient struct {
12
12
client * statsd.Client
13
13
rate float64
14
- tagMap map [ string ]string
14
+ tags [ ]string
15
15
}
16
16
17
17
// NewDataDogClient creates a new dogstatsd client pointing to `address` with
@@ -39,7 +39,7 @@ func (c *DataDogClient) WithRate(rate float64) Client {
39
39
return & DataDogClient {
40
40
client : c .client ,
41
41
rate : rate ,
42
- tagMap : combine ( c . tagMap , map [ string ] string {}),
42
+ tags : c . tags , // clone isn't necessary since original slice is immutable
43
43
}
44
44
}
45
45
@@ -49,22 +49,18 @@ func (c *DataDogClient) WithTags(tags map[string]string) Client {
49
49
return & DataDogClient {
50
50
client : c .client ,
51
51
rate : c .rate ,
52
- tagMap : combine (c .tagMap , tags ),
52
+ tags : cloneTagsWithMap (c .tags , tags ),
53
53
}
54
54
}
55
55
56
- func (c * DataDogClient ) tagsList () []string {
57
- return mapToStrings (c .tagMap )
58
- }
59
-
60
56
// Close closes all client connections and flushes any buffered data.
61
57
func (c * DataDogClient ) Close () error {
62
58
return c .client .Close ()
63
59
}
64
60
65
61
// Count adds some integer value to a metric.
66
62
func (c * DataDogClient ) Count (name string , value int64 ) {
67
- c .client .Count (name , value , c .tagsList () , c .rate )
63
+ c .client .Count (name , value , c .tags , c .rate )
68
64
}
69
65
70
66
// Incr adds one to a metric.
@@ -79,29 +75,29 @@ func (c *DataDogClient) Decr(name string) {
79
75
80
76
// Gauge sets a numeric value.
81
77
func (c * DataDogClient ) Gauge (name string , value float64 ) {
82
- c .client .Gauge (name , value , c .tagsList () , c .rate )
78
+ c .client .Gauge (name , value , c .tags , c .rate )
83
79
}
84
80
85
81
// Event tracks an event that may be relevant to other metrics.
86
82
func (c * DataDogClient ) Event (e * statsd.Event ) {
87
- if len (c .tagMap ) > 0 {
88
- e .Tags = append (e .Tags , c .tagsList () ... )
83
+ if len (c .tags ) > 0 {
84
+ e .Tags = append (e .Tags , c .tags ... )
89
85
}
90
86
91
87
c .client .Event (e )
92
88
}
93
89
94
90
// Timing tracks a duration.
95
91
func (c * DataDogClient ) Timing (name string , value time.Duration ) {
96
- c .client .Timing (name , value , c .tagsList () , c .rate )
92
+ c .client .Timing (name , value , c .tags , c .rate )
97
93
}
98
94
99
95
// Histogram sets a numeric value while tracking min/max/avg/p95/etc.
100
96
func (c * DataDogClient ) Histogram (name string , value float64 ) {
101
- c .client .Histogram (name , value , c .tagsList () , c .rate )
97
+ c .client .Histogram (name , value , c .tags , c .rate )
102
98
}
103
99
104
100
// Distribution tracks the statistical distribution of a set of values.
105
101
func (c * DataDogClient ) Distribution (name string , value float64 ) {
106
- c .client .Distribution (name , value , c .tagsList () , c .rate )
102
+ c .client .Distribution (name , value , c .tags , c .rate )
107
103
}
0 commit comments