Skip to content

Commit 622e6b4

Browse files
committed
minor #60243 [Cache][EventDispatcher][HttpClient][HttpKernel][Messenger][Validator][Workflow] Don't enable tracing unless the profiler is enabled (nicolas-grekas)
This PR was merged into the 7.3 branch. Discussion ---------- [Cache][EventDispatcher][HttpClient][HttpKernel][Messenger][Validator][Workflow] Don't enable tracing unless the profiler is enabled | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | symfony/symfony#60037 | License | MIT This PR ensures traceable decorators are enabled only if the profiler is also enabled. The way it works is by adding a new argument to all traceable decorators: `?\Closure $disabled`. When a closure is given and when the closure returns true, tracing should be skipped. Calling the closure should be done before every decorated method to cope for dynamically enabled/disabled states. Then, this argument is wired using dependency injection so that a closure is passed that returns the current state of the profiler. If the profiler is not instantiated yet (eg because we're on the CLI, or because we're before ProfilerListener enabled it), then a default state is used (disabled on the CLI, enabled on the web). This allows collecting data on the web even if the profiler didn't start yet (as happens when a request comes in, before ProfilerListener is triggered). Note that I didn't change all `Traceable*` decorators: the remaining ones look inoffensive to me. Of course, this could be wrong and fixed in follow up PRs. Commits ------- d5a3769bd05 Don't enable tracing unless the profiler is enabled
2 parents 839d9d4 + 9c041e5 commit 622e6b4

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
$tracedRequest = [

0 commit comments

Comments
 (0)