22
33namespace Cosmastech \StatsDClientAdapter \Adapters \League ;
44
5+ use Cosmastech \StatsDClientAdapter \Adapters \Concerns \HasDefaultTagsTrait ;
56use Cosmastech \StatsDClientAdapter \Adapters \Concerns \TagNormalizerAwareTrait ;
67use Cosmastech \StatsDClientAdapter \Adapters \Contracts \TagNormalizerAware ;
78use Cosmastech \StatsDClientAdapter \Adapters \StatsDClientAdapter ;
1415
1516class LeagueStatsDClientAdapter implements StatsDClientAdapter, TagNormalizerAware
1617{
18+ use HasDefaultTagsTrait;
1719 use TagNormalizerAwareTrait;
1820
1921 public function __construct (
2022 protected readonly LeagueStatsDClientInterface $ leagueStatsDClient ,
21- protected readonly SampleRateSendDeciderInterface $ sampleRateSendDecider
23+ protected readonly SampleRateSendDeciderInterface $ sampleRateSendDecider ,
24+ array $ defaultTags = [],
2225 ) {
26+ $ this ->setDefaultTags ($ defaultTags );
2327 }
2428
2529 /**
@@ -28,12 +32,17 @@ public function __construct(
2832 public static function fromConfig (
2933 array $ config ,
3034 string $ instanceName = 'default ' ,
31- ?SampleRateSendDeciderInterface $ sampleRateSendDecider = null
35+ ?SampleRateSendDeciderInterface $ sampleRateSendDecider = null ,
36+ array $ defaultTags = []
3237 ): static {
3338 $ instance = Client::instance ($ instanceName );
3439 $ instance ->configure ($ config );
3540
36- return new static ($ instance , $ sampleRateSendDecider ?? new SampleRateSendDecider ());
41+ return new self (
42+ $ instance ,
43+ $ sampleRateSendDecider ?? new SampleRateSendDecider (),
44+ $ defaultTags
45+ );
3746 }
3847
3948 /**
@@ -45,7 +54,11 @@ public function timing(string $stat, float $durationMs, float $sampleRate = 1.0,
4554 return ;
4655 }
4756
48- $ this ->leagueStatsDClient ->timing ($ stat , $ durationMs , $ this ->normalizeTags ($ tags ));
57+ $ this ->leagueStatsDClient ->timing (
58+ $ stat ,
59+ $ durationMs ,
60+ $ this ->normalizeTags ($ this ->mergeTags ($ tags ))
61+ );
4962 }
5063
5164 /**
@@ -57,7 +70,11 @@ public function gauge(string $stat, float $value, float $sampleRate = 1.0, array
5770 return ;
5871 }
5972
60- $ this ->leagueStatsDClient ->gauge ($ stat , $ value , $ tags );
73+ $ this ->leagueStatsDClient ->gauge (
74+ $ stat ,
75+ $ value ,
76+ $ this ->normalizeTags ($ this ->mergeTags ($ tags ))
77+ );
6178 }
6279
6380 public function histogram (string $ stat , float $ value , float $ sampleRate = 1.0 , array $ tags = []): void
@@ -79,31 +96,50 @@ public function set(string $stat, float|string $value, float $sampleRate = 1.0,
7996 return ;
8097 }
8198
82- $ this ->leagueStatsDClient ->set ($ stat , $ value , $ tags );
99+ $ this ->leagueStatsDClient ->set (
100+ $ stat ,
101+ $ value ,
102+ $ this ->normalizeTags ($ this ->mergeTags ($ tags ))
103+ );
83104 }
84105
85106 /**
86107 * @throws ConnectionException
87108 */
88109 public function increment (array |string $ stats , float $ sampleRate = 1.0 , array $ tags = [], int $ value = 1 ): void
89110 {
90- $ this ->leagueStatsDClient ->increment ($ stats , $ value , $ sampleRate , $ tags );
111+ $ this ->leagueStatsDClient ->increment (
112+ $ stats ,
113+ $ value ,
114+ $ sampleRate ,
115+ $ this ->normalizeTags ($ this ->mergeTags ($ tags ))
116+ );
91117 }
92118
93119 /**
94120 * @throws ConnectionException
95121 */
96122 public function decrement (array |string $ stats , float $ sampleRate = 1.0 , array $ tags = [], int $ value = 1 ): void
97123 {
98- $ this ->leagueStatsDClient ->decrement ($ stats , $ value , $ sampleRate , $ tags );
124+ $ this ->leagueStatsDClient ->decrement (
125+ $ stats ,
126+ $ value ,
127+ $ sampleRate ,
128+ $ this ->normalizeTags ($ this ->mergeTags ($ tags ))
129+ );
99130 }
100131
101132 /**
102133 * @throws ConnectionException
103134 */
104135 public function updateStats (array |string $ stats , int $ delta = 1 , $ sampleRate = 1.0 , $ tags = null ): void
105136 {
106- $ this ->increment ($ stats , $ sampleRate , $ tags , $ delta );
137+ $ this ->increment (
138+ $ stats ,
139+ $ sampleRate ,
140+ $ this ->normalizeTags ($ this ->mergeTags ($ tags )),
141+ $ delta
142+ );
107143 }
108144
109145 public function getClient (): LeagueStatsDClientInterface
0 commit comments