Skip to content

Commit 27b35e9

Browse files
Merge pull request #5 from istreamlabs/event-tags
Add tags to events automatically
2 parents 5238649 + faa7a02 commit 27b35e9

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
- Add unreleased items here.
10+
11+
## [1.2.0] - 2018-03-01
12+
913
- Update build to test with Go 1.9, drop support for 1.7 since `dep` now
1014
requires Go 1.8+. Go 1.7 users can still use this library but must manage
1115
their own dependencies.
1216
- Add `WithRate(rate float)` to the DataDog client to limit traffic sent to
1317
the `dogstatsd` daemon. The set rate will be applied to all calls made
1418
with the returned `Client`.
19+
- Automatically assign tags to events.
1520

1621
## [1.1.0] - 2017-08-01
1722

metrics/datadog.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (c *DataDogClient) Gauge(name string, value float64) {
7979

8080
// Event tracks an event that may be relevant to other metrics.
8181
func (c *DataDogClient) Event(e *statsd.Event) {
82+
if len(c.tagMap) > 0 {
83+
e.Tags = append(e.Tags, c.tagsList()...)
84+
}
85+
8286
c.client.Event(e)
8387
}
8488

metrics/datadog_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ func TestDataDogClient(t *testing.T) {
6363
if !reflect.DeepEqual(actual, expected) {
6464
t.Fatalf("Expected %v to equal %v", actual, expected)
6565
}
66+
67+
// Events should get tags assigned automatically.
68+
e := &statsd.Event{
69+
Title: "Test event",
70+
}
71+
72+
datadog.WithTags(map[string]string{
73+
"tag1": "value1",
74+
}).Event(e)
75+
76+
if !reflect.DeepEqual(e.Tags, []string{"tag1:value1"}) {
77+
t.Fatalf("Expected event to have tags '[tag1:value1]'. Found '%v'", e.Tags)
78+
}
6679
}

0 commit comments

Comments
 (0)