@@ -108,13 +108,15 @@ public function __construct(array $config = array())
108
108
$ this ->submitEventsOver = 'TCP ' ;
109
109
}
110
110
111
- # by default the telemetry is disable
111
+ // by default the telemetry is disable
112
112
$ this ->disable_telemetry = isset ($ config ["disable_telemetry " ]) ? $ config ["disable_telemetry " ] : true ;
113
113
$ transport_type = !is_null ($ this ->socketPath ) ? "uds " : "udp " ;
114
- $ this ->telemetry_tags = $ this ->serializeTags (array (
114
+ $ this ->telemetry_tags = $ this ->serializeTags (
115
+ array (
115
116
"client " => "php " ,
116
117
"client_version " => self ::$ version ,
117
- "client_transport " => $ transport_type ));
118
+ "client_transport " => $ transport_type )
119
+ );
118
120
119
121
$ this ->resetTelemetry ();
120
122
}
@@ -153,10 +155,10 @@ private function flushTelemetry()
153
155
/**
154
156
* Log timing information
155
157
*
156
- * @param string $stat The metric to in log timing info for.
157
- * @param float $time The elapsed time (ms) to log
158
- * @param float $sampleRate the rate (0-1) for sampling.
159
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
158
+ * @param string $stat The metric to in log timing info for.
159
+ * @param float $time The elapsed time (ms) to log
160
+ * @param float $sampleRate the rate (0-1) for sampling.
161
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
160
162
* @return void
161
163
*/
162
164
public function timing ($ stat , $ time , $ sampleRate = 1.0 , $ tags = null )
@@ -168,10 +170,10 @@ public function timing($stat, $time, $sampleRate = 1.0, $tags = null)
168
170
/**
169
171
* A convenient alias for the timing function when used with micro-timing
170
172
*
171
- * @param string $stat The metric name
172
- * @param float $time The elapsed time to log, IN SECONDS
173
- * @param float $sampleRate the rate (0-1) for sampling.
174
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
173
+ * @param string $stat The metric name
174
+ * @param float $time The elapsed time to log, IN SECONDS
175
+ * @param float $sampleRate the rate (0-1) for sampling.
176
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
175
177
* @return void
176
178
**/
177
179
public function microtiming ($ stat , $ time , $ sampleRate = 1.0 , $ tags = null )
@@ -182,10 +184,10 @@ public function microtiming($stat, $time, $sampleRate = 1.0, $tags = null)
182
184
/**
183
185
* Gauge
184
186
*
185
- * @param string $stat The metric
186
- * @param float $value The value
187
- * @param float $sampleRate the rate (0-1) for sampling.
188
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
187
+ * @param string $stat The metric
188
+ * @param float $value The value
189
+ * @param float $sampleRate the rate (0-1) for sampling.
190
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
189
191
* @return void
190
192
**/
191
193
public function gauge ($ stat , $ value , $ sampleRate = 1.0 , $ tags = null )
@@ -197,10 +199,10 @@ public function gauge($stat, $value, $sampleRate = 1.0, $tags = null)
197
199
/**
198
200
* Histogram
199
201
*
200
- * @param string $stat The metric
201
- * @param float $value The value
202
- * @param float $sampleRate the rate (0-1) for sampling.
203
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
202
+ * @param string $stat The metric
203
+ * @param float $value The value
204
+ * @param float $sampleRate the rate (0-1) for sampling.
205
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
204
206
* @return void
205
207
**/
206
208
public function histogram ($ stat , $ value , $ sampleRate = 1.0 , $ tags = null )
@@ -212,10 +214,10 @@ public function histogram($stat, $value, $sampleRate = 1.0, $tags = null)
212
214
/**
213
215
* Distribution
214
216
*
215
- * @param string $stat The metric
216
- * @param float $value The value
217
- * @param float $sampleRate the rate (0-1) for sampling.
218
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
217
+ * @param string $stat The metric
218
+ * @param float $value The value
219
+ * @param float $sampleRate the rate (0-1) for sampling.
220
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
219
221
* @return void
220
222
**/
221
223
public function distribution ($ stat , $ value , $ sampleRate = 1.0 , $ tags = null )
@@ -227,10 +229,10 @@ public function distribution($stat, $value, $sampleRate = 1.0, $tags = null)
227
229
/**
228
230
* Set
229
231
*
230
- * @param string $stat The metric
231
- * @param float $value The value
232
- * @param float $sampleRate the rate (0-1) for sampling.
233
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
232
+ * @param string $stat The metric
233
+ * @param float $value The value
234
+ * @param float $sampleRate the rate (0-1) for sampling.
235
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
234
236
* @return void
235
237
**/
236
238
public function set ($ stat , $ value , $ sampleRate = 1.0 , $ tags = null )
@@ -243,10 +245,10 @@ public function set($stat, $value, $sampleRate = 1.0, $tags = null)
243
245
/**
244
246
* Increments one or more stats counters
245
247
*
246
- * @param string|array $stats The metric(s) to increment.
247
- * @param float $sampleRate the rate (0-1) for sampling.
248
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
249
- * @param int $value the amount to increment by (default 1)
248
+ * @param string|array $stats The metric(s) to increment.
249
+ * @param float $sampleRate the rate (0-1) for sampling.
250
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
251
+ * @param int $value the amount to increment by (default 1)
250
252
* @return void
251
253
**/
252
254
public function increment ($ stats , $ sampleRate = 1.0 , $ tags = null , $ value = 1 )
@@ -257,10 +259,10 @@ public function increment($stats, $sampleRate = 1.0, $tags = null, $value = 1)
257
259
/**
258
260
* Decrements one or more stats counters.
259
261
*
260
- * @param string|array $stats The metric(s) to decrement.
261
- * @param float $sampleRate the rate (0-1) for sampling.
262
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
263
- * @param int $value the amount to decrement by (default -1)
262
+ * @param string|array $stats The metric(s) to decrement.
263
+ * @param float $sampleRate the rate (0-1) for sampling.
264
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
265
+ * @param int $value the amount to decrement by (default -1)
264
266
* @return void
265
267
**/
266
268
public function decrement ($ stats , $ sampleRate = 1.0 , $ tags = null , $ value = -1 )
@@ -274,10 +276,10 @@ public function decrement($stats, $sampleRate = 1.0, $tags = null, $value = -1)
274
276
/**
275
277
* Updates one or more stats counters by arbitrary amounts.
276
278
*
277
- * @param string|array $stats The metric(s) to update. Should be either a string or array of metrics.
278
- * @param int $delta The amount to increment/decrement each metric by.
279
- * @param float $sampleRate the rate (0-1) for sampling.
280
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
279
+ * @param string|array $stats The metric(s) to update. Should be either a string or array of metrics.
280
+ * @param int $delta The amount to increment/decrement each metric by.
281
+ * @param float $sampleRate the rate (0-1) for sampling.
282
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
281
283
* @return void
282
284
**/
283
285
public function updateStats ($ stats , $ delta = 1 , $ sampleRate = 1.0 , $ tags = null )
@@ -296,7 +298,7 @@ public function updateStats($stats, $delta = 1, $sampleRate = 1.0, $tags = null)
296
298
/**
297
299
* Serialize tags to StatsD protocol
298
300
*
299
- * @param string|array $tags The tags to be serialize
301
+ * @param string|array $tags The tags to be serialize
300
302
* @return string
301
303
**/
302
304
private function serializeTags ($ tags )
@@ -323,7 +325,7 @@ private function serializeTags($tags)
323
325
/**
324
326
* Turns tags in any format into an array of tags
325
327
*
326
- * @param mixed $tags The tags to normalize
328
+ * @param mixed $tags The tags to normalize
327
329
* @return array
328
330
*/
329
331
private function normalizeTags ($ tags )
@@ -358,9 +360,10 @@ private function normalizeTags($tags)
358
360
359
361
/**
360
362
* Squirt the metrics over UDP
361
- * @param array $data Incoming Data
362
- * @param float $sampleRate the rate (0-1) for sampling.
363
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
363
+ *
364
+ * @param array $data Incoming Data
365
+ * @param float $sampleRate the rate (0-1) for sampling.
366
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
364
367
* @return void
365
368
**/
366
369
public function send ($ data , $ sampleRate = 1.0 , $ tags = null )
@@ -392,13 +395,13 @@ public function send($data, $sampleRate = 1.0, $tags = null)
392
395
* @deprecated service_check will be removed in future versions in favor of serviceCheck
393
396
*
394
397
* Send a custom service check status over UDP
395
- * @param string $name service check name
396
- * @param int $status service check status code (see OK, WARNING,...)
397
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
398
- * @param string $hostname hostname to associate with this service check status
399
- * @param string $message message to associate with this service check status
400
- * @param int $timestamp timestamp for the service check status (defaults to now)
401
- * @return void
398
+ * @param string $name service check name
399
+ * @param int $status service check status code (see OK, WARNING,...)
400
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
401
+ * @param string $hostname hostname to associate with this service check status
402
+ * @param string $message message to associate with this service check status
403
+ * @param int $timestamp timestamp for the service check status (defaults to now)
404
+ * @return void
402
405
**/
403
406
public function service_check ( // phpcs:ignore
404
407
$ name ,
@@ -413,12 +416,13 @@ public function service_check( // phpcs:ignore
413
416
414
417
/**
415
418
* Send a custom service check status over UDP
416
- * @param string $name service check name
417
- * @param int $status service check status code (see OK, WARNING,...)
418
- * @param array|string $tags Key Value array of Tag => Value, or single tag as string
419
- * @param string $hostname hostname to associate with this service check status
420
- * @param string $message message to associate with this service check status
421
- * @param int $timestamp timestamp for the service check status (defaults to now)
419
+ *
420
+ * @param string $name service check name
421
+ * @param int $status service check status code (see OK, WARNING,...)
422
+ * @param array|string $tags Key Value array of Tag => Value, or single tag as string
423
+ * @param string $hostname hostname to associate with this service check status
424
+ * @param string $message message to associate with this service check status
425
+ * @param int $timestamp timestamp for the service check status (defaults to now)
422
426
* @return void
423
427
**/
424
428
public function serviceCheck (
@@ -488,9 +492,10 @@ public function flush($message)
488
492
* making many call in a row if you don't want to stall your app.
489
493
* Requires PHP >= 5.3.0
490
494
*
491
- * @param string $title Title of the event
492
- * @param array $vals Optional values of the event. See
493
- * https://docs.datadoghq.com/api/?lang=bash#post-an-event for the valid keys
495
+ * @param string $title Title of the event
496
+ * @param array $vals Optional values of the event. See
497
+ * https://docs.datadoghq.com/api/?lang=bash#post-an-event
498
+ * for the valid keys
494
499
* @return null
495
500
**/
496
501
public function event ($ title , $ vals = array ())
@@ -500,7 +505,7 @@ public function event($title, $vals = array())
500
505
$ vals ['title ' ] = $ title ;
501
506
502
507
// If sending events via UDP
503
- if ($ this ->submitEventsOver === 'UDP ' ) { # FIX
508
+ if ($ this ->submitEventsOver === 'UDP ' ) { // FIX
504
509
return $ this ->eventUdp ($ vals );
505
510
}
506
511
@@ -541,8 +546,10 @@ public function event($title, $vals = array())
541
546
542
547
// Check response code is 202
543
548
if ($ response_code !== 200 && $ response_code !== 202 ) {
544
- throw new \Exception ('Datadog event API call HTTP response not OK - '
545
- . $ response_code . '; response body: ' . $ response_body );
549
+ throw new \Exception (
550
+ 'Datadog event API call HTTP response not OK - '
551
+ . $ response_code . '; response body: ' . $ response_body
552
+ );
546
553
}
547
554
548
555
// Check for empty response body
@@ -552,14 +559,18 @@ public function event($title, $vals = array())
552
559
553
560
// Decode JSON response
554
561
if (!$ decodedJson = json_decode ($ response_body , true )) {
555
- throw new \Exception ('Datadog event API call did not return a body '
556
- . ' that could be decoded via json_decode ' );
562
+ throw new \Exception (
563
+ 'Datadog event API call did not return a body '
564
+ . ' that could be decoded via json_decode '
565
+ );
557
566
}
558
567
559
568
// Check JSON decoded "status" is OK from the Datadog API
560
569
if ($ decodedJson ['status ' ] !== 'ok ' ) {
561
- throw new \Exception ('Datadog event API response status not "ok"; response body: '
562
- . $ response_body );
570
+ throw new \Exception (
571
+ 'Datadog event API response status not "ok"; response body: '
572
+ . $ response_body
573
+ );
563
574
}
564
575
} catch (\Exception $ e ) {
565
576
$ success = false ;
@@ -574,8 +585,9 @@ public function event($title, $vals = array())
574
585
575
586
/**
576
587
* Formats $vals array into event for submission to Datadog via UDP
577
- * @param array $vals Optional values of the event. See
578
- * https://docs.datadoghq.com/api/?lang=bash#post-an-event for the valid keys
588
+ *
589
+ * @param array $vals Optional values of the event. See
590
+ * https://docs.datadoghq.com/api/?lang=bash#post-an-event for the valid keys
579
591
* @return null
580
592
*/
581
593
private function eventUdp ($ vals )
0 commit comments