Skip to content

Commit 9c041e5

Browse files
Don't enable tracing unless the profiler is enabled
1 parent 02a2e8b commit 9c041e5

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

DependencyInjection/HttpClientPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function process(ContainerBuilder $container): void
2727

2828
foreach ($container->findTaggedServiceIds('http_client.client') as $id => $tags) {
2929
$container->register('.debug.'.$id, TraceableHttpClient::class)
30-
->setArguments([new Reference('.debug.'.$id.'.inner'), new Reference('debug.stopwatch', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
30+
->setArguments([new Reference('.debug.'.$id.'.inner'), new Reference('debug.stopwatch', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new Reference('profiler.is_disabled_state_checker', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
3131
->addTag('kernel.reset', ['method' => 'reset'])
3232
->setDecoratedService($id, null, 5);
3333
$container->getDefinition('data_collector.http_client')

Response/TraceableResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TraceableResponse implements ResponseInterface, StreamableInterface
3434
public function __construct(
3535
private HttpClientInterface $client,
3636
private ResponseInterface $response,
37-
private mixed &$content,
37+
private mixed &$content = false,
3838
private ?StopwatchEvent $event = null,
3939
) {
4040
}

TraceableHttpClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ final class TraceableHttpClient implements HttpClientInterface, ResetInterface,
3131
public function __construct(
3232
private HttpClientInterface $client,
3333
private ?Stopwatch $stopwatch = null,
34+
private ?\Closure $disabled = null,
3435
) {
3536
$this->tracedRequests = new \ArrayObject();
3637
}
3738

3839
public function request(string $method, string $url, array $options = []): ResponseInterface
3940
{
41+
if ($this->disabled?->__invoke()) {
42+
return new TraceableResponse($this->client, $this->client->request($method, $url, $options));
43+
}
44+
4045
$content = null;
4146
$traceInfo = [];
4247
$this->tracedRequests[] = [

0 commit comments

Comments
 (0)