-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_memory.php
53 lines (44 loc) · 1.21 KB
/
in_memory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require_once __DIR__ . "/../vendor/autoload.php";
function timeInMilliseconds()
{
return time() * 1000;
}
function makeApiRequest()
{
sleep(1);
}
$inMemoryAdapter = new \Cosmastech\StatsDClientAdapter\Adapters\InMemory\InMemoryClientAdapter();
$inMemoryAdapter->setDefaultTags(["app_version" => "2.83.0"]); // Set this for tags you want included in all stats.
$startTimeInMs = timeInMilliseconds();
makeApiRequest();
$inMemoryAdapter->timing("api-response", timeInMilliseconds() - $startTimeInMs, 1.0, ["source" => "github"]);
/** @var \Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryStatsRecord $stats */
$stats = $inMemoryAdapter->getStats();
var_dump($stats->getTimings()[0]);
/*
object(Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryTimingRecord)#7 (5) {
["stat"]=>
string(12) "api-response"
["durationMilliseconds"]=>
float(2000)
["sampleRate"]=>
float(1)
["tags"]=>
array(2) {
["app_version"]=>
string(6) "2.83.0"
["source"]=>
string(6) "github"
}
["recordedAt"]=>
object(DateTimeImmutable)#8 (3) {
["date"]=>
string(26) "2024-07-08 22:25:53.080522"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
}
*/