From de905ed5df059054376c24f90d27bc863c727976 Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 25 Jul 2025 00:35:12 +0200 Subject: [PATCH] Fix console tracing I noticed that our project lacks spans when executing console commands. I found that upon completion of a console command, only one specific span is finalized, rather than the entire transaction, unlike the behavior in TracingRequestListener. After locally modifying it to complete the transaction and running console sentry:test, I observed the other spans that were previously missing. Therefore, I believe this fix should resolve the issue. --- src/EventListener/TracingConsoleListener.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/EventListener/TracingConsoleListener.php b/src/EventListener/TracingConsoleListener.php index 57c187a6..68440514 100644 --- a/src/EventListener/TracingConsoleListener.php +++ b/src/EventListener/TracingConsoleListener.php @@ -91,11 +91,12 @@ public function handleConsoleTerminateEvent(ConsoleTerminateEvent $event): void return; } - $span = $this->hub->getSpan(); + $transaction = $this->hub->getTransaction(); - if (null !== $span) { - $span->setStatus(0 === $event->getExitCode() ? SpanStatus::ok() : SpanStatus::internalError()); - $span->finish(); + if (null !== $transaction) { + $transaction->setStatus(0 === $event->getExitCode() ? SpanStatus::ok() : SpanStatus::internalError()); + $transaction->finish(); + metrics()->flush(); } }