@@ -38,25 +38,12 @@ public function registerClient(string $name, TraceableHttpClient $client)
38
38
*/
39
39
public function collect (Request $ request , Response $ response , \Throwable $ exception = null )
40
40
{
41
+ $ this ->doCollect (false );
41
42
}
42
43
43
44
public function lateCollect ()
44
45
{
45
- $ this ->reset ();
46
-
47
- foreach ($ this ->clients as $ name => $ client ) {
48
- [$ errorCount , $ traces ] = $ this ->collectOnClient ($ client );
49
-
50
- $ this ->data ['clients ' ][$ name ] = [
51
- 'traces ' => $ traces ,
52
- 'error_count ' => $ errorCount ,
53
- ];
54
-
55
- $ this ->data ['request_count ' ] += \count ($ traces );
56
- $ this ->data ['error_count ' ] += $ errorCount ;
57
-
58
- $ client ->reset ();
59
- }
46
+ $ this ->doCollect (true );
60
47
}
61
48
62
49
public function getClients (): array
@@ -91,6 +78,28 @@ public function reset()
91
78
];
92
79
}
93
80
81
+ private function doCollect (bool $ reset )
82
+ {
83
+ $ this ->data ['request_count ' ] = 0 ;
84
+ $ this ->data ['error_count ' ] = 0 ;
85
+
86
+ foreach ($ this ->clients as $ name => $ client ) {
87
+ [$ errorCount , $ traces ] = $ this ->collectOnClient ($ client );
88
+
89
+ $ this ->data ['clients ' ][$ name ] = [
90
+ 'traces ' => $ traces ,
91
+ 'error_count ' => $ errorCount ,
92
+ ];
93
+
94
+ $ this ->data ['request_count ' ] += \count ($ traces );
95
+ $ this ->data ['error_count ' ] += $ errorCount ;
96
+
97
+ if ($ reset ) {
98
+ $ client ->reset ();
99
+ }
100
+ }
101
+ }
102
+
94
103
private function collectOnClient (TraceableHttpClient $ client ): array
95
104
{
96
105
$ traces = $ client ->getTracedRequests ();
0 commit comments