From f322cb84fbcece5f22e94b6f4bdb1107cf35f6ec Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Tue, 23 Dec 2025 08:58:59 +0800 Subject: [PATCH 1/2] feat(sentry): add singleton support for Logs class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add \Sentry\Logs\Logs::getInstance to SingletonAspect whitelist - Move Logs::getInstance()->flush() outside client null check for proper cleanup - Ensure Logs singleton instances are properly isolated per coroutine context 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/sentry/src/Aspect/SingletonAspect.php | 4 +++- src/sentry/src/Integration.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sentry/src/Aspect/SingletonAspect.php b/src/sentry/src/Aspect/SingletonAspect.php index 089e2a86c..d64e5c2c8 100644 --- a/src/sentry/src/Aspect/SingletonAspect.php +++ b/src/sentry/src/Aspect/SingletonAspect.php @@ -22,6 +22,7 @@ class SingletonAspect extends AbstractAspect // Singleton Classes \Sentry\State\HubAdapter::class . '::getInstance', \Sentry\Integration\IntegrationRegistry::class . '::getInstance', + \Sentry\Logs\Logs::class . '::getInstance', \Sentry\Metrics\TraceMetrics::class . '::getInstance', // Enums // \Sentry\CheckInStatus::class . '::getInstance', @@ -46,7 +47,8 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) return match ($className) { // Singleton Classes \Sentry\State\HubAdapter::class, - \Sentry\Integration\IntegrationRegistry::class => Context::getOrSet($key, function () use ($className) { + \Sentry\Integration\IntegrationRegistry::class, + \Sentry\Logs\Logs::class => Context::getOrSet($key, function () use ($className) { return Closure::bind(fn () => new $className(), null, $className)(); }), \Sentry\Metrics\TraceMetrics::class => Context::getOrSet($key, function () use ($className) { diff --git a/src/sentry/src/Integration.php b/src/sentry/src/Integration.php index e26f0e80e..dd3bfa1ce 100644 --- a/src/sentry/src/Integration.php +++ b/src/sentry/src/Integration.php @@ -110,10 +110,10 @@ public static function flushEvents(): void if ($client !== null) { $client->flush(); - - Logs::getInstance()->flush(); - TraceMetrics::getInstance()->flush(); } + + Logs::getInstance()->flush(); + TraceMetrics::getInstance()->flush(); } /** From a7cc6aed70b8ea54ec77710523b1ade0df827270 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Tue, 23 Dec 2025 09:01:08 +0800 Subject: [PATCH 2/2] fix(sentry): simplify flushEvents method by using nullsafe operator --- src/sentry/src/Integration.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/sentry/src/Integration.php b/src/sentry/src/Integration.php index dd3bfa1ce..4dff02b2e 100644 --- a/src/sentry/src/Integration.php +++ b/src/sentry/src/Integration.php @@ -106,12 +106,7 @@ public static function setTransaction(?string $transaction): void */ public static function flushEvents(): void { - $client = SentrySdk::getCurrentHub()->getClient(); - - if ($client !== null) { - $client->flush(); - } - + SentrySdk::getCurrentHub()->getClient()?->flush(); Logs::getInstance()->flush(); TraceMetrics::getInstance()->flush(); }