Skip to content

Commit cca73e7

Browse files
[HttpClient] Fix collecting data non-late for the profiler
1 parent aa82db9 commit cca73e7

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,12 @@ public function registerClient(string $name, TraceableHttpClient $client)
3838
*/
3939
public function collect(Request $request, Response $response, \Throwable $exception = null)
4040
{
41+
$this->doCollect(false);
4142
}
4243

4344
public function lateCollect()
4445
{
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);
6047
}
6148

6249
public function getClients(): array
@@ -91,6 +78,28 @@ public function reset()
9178
];
9279
}
9380

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+
94103
private function collectOnClient(TraceableHttpClient $client): array
95104
{
96105
$traces = $client->getTracedRequests();

0 commit comments

Comments
 (0)