8000 minor #60243 [Cache][EventDispatcher][HttpClient][HttpKernel][Messeng… · symfony/messenger@54a70d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54a70d7

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 f9cf69a + af38722 commit 54a70d7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

DependencyInjection/MessengerPass.php

Lines changed: 1 addition & 1 deletio 8000 n
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private function registerBusToCollector(ContainerBuilder $container, string $bus
337337
{
338338
$container->setDefinition(
339339
$tracedBusId = 'debug.traced.'.$busId,
340-
(new Definition(TraceableMessageBus::class, [new Reference($tracedBusId.'.inner')]))->setDecoratedService($busId)
340+
(new Definition(TraceableMessageBus::class, [new Reference($tracedBusId.'.inner'), new Reference('profiler.is_disabled_state_checker', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE)]))->setDecoratedService($busId)
341341
);
342342

343343
$container->getDefinition('data_collector.messenger')->addMethodCall('registerBus', [$busId, new Reference($tracedBusId)]);

TraceableMessageBus.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ class TraceableMessageBus implements MessageBusInterface
2020

2121
public function __construct(
2222
private MessageBusInterface $decoratedBus,
23+
protected readonly ?\Closure $disabled = null,
2324
) {
2425
}
2526

2627
public function dispatch(object $message, array $stamps = []): Envelope
2728
{
29+
if ($this->disabled?->__invoke()) {
30+
return $this->decoratedBus->dispatch($message, $stamps);
31+
}
32+
2833
$envelope = Envelope::wrap($message, $stamps);
2934
$context = [
3035
'stamps' => array_merge([], ...array_values($envelope->all())),

0 commit comments

Comments
 (0)
0