From e49fc986155e6b3c5588f7f0443de530d3f3a2cb Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Mon, 7 Feb 2022 17:01:33 -0500 Subject: [PATCH] Include default tags for events and service checks --- src/Client.php | 4 ++-- tests/unit/TagsTest.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 4c2ab1f..db152be 100644 --- a/src/Client.php +++ b/src/Client.php @@ -564,7 +564,7 @@ public function event($title, $text, array $metadata = [], array $tags = []) } } - $value .= $this->formatTags($tags); + $value .= $this->formatTags($this->processTags(array_merge($this->tags, $tags))); return $this->sendMessages([ sprintf('%s:%s', $metric, $value), @@ -604,7 +604,7 @@ public function serviceCheck($name, $status, array $metadata = [], array $tags = }; $applyMetadata($metadata, $this->serviceCheckMetaData); - $value .= $this->formatTags($tags); + $value .= $this->formatTags($this->processTags(array_merge($this->tags, $tags))); $applyMetadata($metadata, $this->serviceCheckMessage); return $this->sendMessages([ diff --git a/tests/unit/TagsTest.php b/tests/unit/TagsTest.php index ad5f06c..dc56748 100644 --- a/tests/unit/TagsTest.php +++ b/tests/unit/TagsTest.php @@ -13,6 +13,7 @@ namespace Graze\DogStatsD\Test\Unit; +use Graze\DogStatsD\Client; use Graze\DogStatsD\Test\TestCase; class TagsTest extends TestCase @@ -52,4 +53,24 @@ public function testDefaultTagsGetAddedToRequest() $this->client->increment('test_metric', 1, 1, ['tag2']); $this->assertEquals('test_metric:1|c|#tag1,tag2', $this->client->getLastMessage()); } + + public function testDefaultTagsGetAddedToEventRequest() + { + $this->client->configure([ + 'tags' => ['tag1'], + ]); + + $this->client->event('some_title', 'textAndThings', [], ['tag2']); + $this->assertEquals('_e{10,13}:some_title|textAndThings|#tag1,tag2', $this->client->getLastMessage()); + } + + public function testDefaultTagsGetAddedToServiceCheckRequest() + { + $this->client->configure([ + 'tags' => ['tag1'], + ]); + + $this->client->serviceCheck('service.api', Client::STATUS_OK, [], ['tag2']); + $this->assertEquals('_sc|service.api|0|#tag1,tag2', $this->client->getLastMessage()); + } }