Skip to content

Commit db2648a

Browse files
feat(shutdown): flush OTel on AfterHandle and AfterExecute events
Ensures traces and metrics are flushed when a Hyperf CLI command exits, in addition to the existing OnWorkerExit handler. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent aee31a3 commit db2648a

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/Listener/OtelShutdownListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Hyperf\OpenTelemetry\Listener;
66

7+
use Hyperf\Command\Event\AfterExecute;
8+
use Hyperf\Command\Event\AfterHandle;
79
use Hyperf\Contract\StdoutLoggerInterface;
810
use Hyperf\Coroutine\Coroutine;
911
use Hyperf\Event\Contract\ListenerInterface;
@@ -25,6 +27,8 @@ public function listen(): array
2527
{
2628
return [
2729
OnWorkerExit::class,
30+
AfterHandle::class,
31+
AfterExecute::class,
2832
];
2933
}
3034

tests/Unit/Listener/OtelShutdownListenerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tests\Unit\Listener;
66

7+
use Hyperf\Command\Event\AfterExecute;
8+
use Hyperf\Command\Event\AfterHandle;
79
use Hyperf\Contract\StdoutLoggerInterface;
810
use Hyperf\Event\Contract\ListenerInterface;
911
use Hyperf\Framework\Event\OnWorkerExit;
@@ -36,7 +38,7 @@ public function testListensToOnWorkerExit(): void
3638
$this->createMock(TracerProviderInterface::class),
3739
$this->createMock(StdoutLoggerInterface::class)
3840
);
39-
$this->assertSame([OnWorkerExit::class], $listener->listen());
41+
$this->assertSame([OnWorkerExit::class, AfterHandle::class, AfterExecute::class], $listener->listen());
4042
}
4143

4244
public function testProcessCallsShutdownInsideCoroutine(): void

0 commit comments

Comments
 (0)