From 9716e0e2fceea4e5e90571f8c62f216291042313 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:29:48 +0800 Subject: [PATCH 01/10] feat: enhance Sentry metrics with configurable default metrics collection - Add SENTRY_ENABLE_DEFAULT_METRICS configuration option - Implement isDefaultMetricsEnabled() method in Feature class - Extend OnBeforeHandle listener to collect command-line metrics - Add worker identification tags to memory metrics - Separate default metrics from custom metrics collection - Add Timer-based periodic metrics collection for commands - Include garbage collection and resource usage metrics This enhancement provides more granular control over metrics collection and extends monitoring capabilities to command-line operations. --- src/sentry/publish/sentry.php | 1 + .../src/Factory/ClientBuilderFactory.php | 1 + src/sentry/src/Feature.php | 9 ++ .../src/Metrics/Listener/OnBeforeHandle.php | 84 +++++++++++++++++-- .../Listener/OnCoroutineServerStart.php | 8 +- .../Metrics/Listener/OnMetricFactoryReady.php | 2 +- .../src/Metrics/Listener/OnWorkerStart.php | 2 +- .../src/Metrics/Traits/MetricSetter.php | 4 + 8 files changed, 102 insertions(+), 9 deletions(-) diff --git a/src/sentry/publish/sentry.php b/src/sentry/publish/sentry.php index dd3187711..afab9829e 100644 --- a/src/sentry/publish/sentry.php +++ b/src/sentry/publish/sentry.php @@ -42,6 +42,7 @@ // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#enable_metrics 'enable_metrics' => env('SENTRY_ENABLE_METRICS', true), + 'enable_default_metrics' => env('SENTRY_ENABLE_DEFAULT_METRICS', true), 'metrics_interval' => (int) env('SENTRY_METRICS_INTERVAL', 10), 'logs_channel_level' => env('SENTRY_LOGS_CHANNEL_LEVEL', Sentry\Logs\LogLevel::debug()), diff --git a/src/sentry/src/Factory/ClientBuilderFactory.php b/src/sentry/src/Factory/ClientBuilderFactory.php index ce478b03b..30ebf72b2 100644 --- a/src/sentry/src/Factory/ClientBuilderFactory.php +++ b/src/sentry/src/Factory/ClientBuilderFactory.php @@ -31,6 +31,7 @@ class ClientBuilderFactory 'http_chanel_size', // deprecated, will be removed in v3.2 'http_concurrent_limit', // deprecated, will be removed in v3.2 'logs_channel_level', + 'enable_default_metrics', 'metrics_interval', 'transport_channel_size', 'transport_concurrent_limit', diff --git a/src/sentry/src/Feature.php b/src/sentry/src/Feature.php index 6b0169af5..dda8491c6 100644 --- a/src/sentry/src/Feature.php +++ b/src/sentry/src/Feature.php @@ -36,6 +36,15 @@ public function isMetricsEnabled(bool $default = true): bool return (bool) $this->config->get('sentry.enable_metrics', $default); } + public function isDefaultMetricsEnabled(bool $default = true): bool + { + if (! $this->isMetricsEnabled()) { + return false; + } + + return (bool) $this->config->get('sentry.enable_default_metrics', $default); + } + public function getMetricsInterval(int $default = 10): int { $interval = (int) $this->config->get('sentry.metrics_interval', $default); diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index b4954ee83..db0e19643 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -12,13 +12,30 @@ namespace FriendsOfHyperf\Sentry\Metrics\Listener; use FriendsOfHyperf\Sentry\Constants; +use FriendsOfHyperf\Sentry\Feature; +use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; use Hyperf\Command\Event\AfterExecute; use Hyperf\Command\Event\BeforeHandle; use Hyperf\Context\Context; +use Hyperf\Coordinator\CoordinatorManager; +use Hyperf\Coordinator\Timer; +use Hyperf\Engine\Coroutine; use Hyperf\Event\Contract\ListenerInterface; +use Sentry\Unit; + +use function FriendsOfHyperf\Sentry\metrics; class OnBeforeHandle implements ListenerInterface { + use MetricSetter; + + protected Timer $timer; + + public function __construct(protected Feature $feature) + { + $this->timer = new Timer(); + } + public function listen(): array { return [ @@ -32,10 +49,67 @@ public function listen(): array */ public function process(object $event): void { - match (true) { - $event instanceof BeforeHandle => Context::set(Constants::RUN_IN_COMMAND, true), - $event instanceof AfterExecute => Context::destroy(Constants::RUN_IN_COMMAND), - default => null, - }; + if ($event instanceof AfterExecute) { + Context::destroy(Constants::RUN_IN_COMMAND); + return; + } + + Context::set(Constants::RUN_IN_COMMAND, true); + + if (! $this->feature->isDefaultMetricsEnabled()) { + return; + } + + // The following metrics MUST be collected in worker. + $metrics = [ + 'memory_usage', + 'memory_peak_usage', + 'gc_runs', + 'gc_collected', + 'gc_threshold', + 'gc_roots', + 'ru_oublock', + 'ru_inblock', + 'ru_msgsnd', + 'ru_msgrcv', + 'ru_maxrss', + 'ru_ixrss', + 'ru_idrss', + 'ru_minflt', + 'ru_majflt', + 'ru_nsignals', + 'ru_nvcsw', + 'ru_nivcsw', + 'ru_nswap', + 'ru_utime_tv_usec', + 'ru_utime_tv_sec', + 'ru_stime_tv_usec', + 'ru_stime_tv_sec', + ]; + + $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () use ($metrics) { + defer(fn () => metrics()->flush()); + + $this->trySet('gc_', $metrics, gc_status()); + $this->trySet('', $metrics, getrusage()); + + metrics()->gauge( + 'memory_usage', + (float) memory_get_usage(), + ['worker' => 'N/A'], + Unit::byte() + ); + metrics()->gauge( + 'memory_peak_usage', + (float) memory_get_peak_usage(), + ['worker' => 'N/A'], + Unit::byte() + ); + }); + + Coroutine::create(function () use ($timerId) { + CoordinatorManager::until(\Hyperf\Coordinator\Constants::WORKER_EXIT)->yield(); + $this->timer->clear($timerId); + }); } } diff --git a/src/sentry/src/Metrics/Listener/OnCoroutineServerStart.php b/src/sentry/src/Metrics/Listener/OnCoroutineServerStart.php index 53dd0141b..f06287729 100644 --- a/src/sentry/src/Metrics/Listener/OnCoroutineServerStart.php +++ b/src/sentry/src/Metrics/Listener/OnCoroutineServerStart.php @@ -67,6 +67,10 @@ public function process(object $event): void $eventDispatcher = $this->container->get(EventDispatcherInterface::class); $eventDispatcher->dispatch(new MetricFactoryReady()); + if (! $this->feature->isDefaultMetricsEnabled()) { + return; + } + // The following metrics MUST be collected in worker. $metrics = [ // 'worker_request_count', @@ -105,13 +109,13 @@ public function process(object $event): void metrics()->gauge( 'memory_usage', (float) memory_get_usage(), - [], + ['worker' => '0'], Unit::byte() ); metrics()->gauge( 'memory_peak_usage', (float) memory_get_peak_usage(), - [], + ['worker' => '0'], Unit::byte() ); }); diff --git a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php index 21b65ca82..d14aa38fe 100644 --- a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php +++ b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php @@ -54,7 +54,7 @@ public function listen(): array */ public function process(object $event): void { - if (! $this->feature->isMetricsEnabled()) { + if ($this->feature->isDefaultMetricsEnabled()) { return; } diff --git a/src/sentry/src/Metrics/Listener/OnWorkerStart.php b/src/sentry/src/Metrics/Listener/OnWorkerStart.php index f6f0c64d1..26372526d 100644 --- a/src/sentry/src/Metrics/Listener/OnWorkerStart.php +++ b/src/sentry/src/Metrics/Listener/OnWorkerStart.php @@ -53,7 +53,7 @@ public function listen(): array */ public function process(object $event): void { - if (! $this->feature->isMetricsEnabled()) { + if (! $this->feature->isDefaultMetricsEnabled()) { return; } diff --git a/src/sentry/src/Metrics/Traits/MetricSetter.php b/src/sentry/src/Metrics/Traits/MetricSetter.php index 9b5a5f9db..89708ae0b 100644 --- a/src/sentry/src/Metrics/Traits/MetricSetter.php +++ b/src/sentry/src/Metrics/Traits/MetricSetter.php @@ -31,4 +31,8 @@ protected function trySet(string $prefix, array $metrics, array $stats, int $wor } } } + + // protected function spawnDefaultMetrics() + // { + // } } From f4a613addf330fe3770ba1390f9c08da7eb67355 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:32:23 +0800 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=8C=87=E6=A0=87=E5=90=AF=E7=94=A8=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/publish/sentry.php | 1 + src/sentry/src/Factory/ClientBuilderFactory.php | 1 + src/sentry/src/Feature.php | 9 +++++++++ src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sentry/publish/sentry.php b/src/sentry/publish/sentry.php index afab9829e..b9e47c553 100644 --- a/src/sentry/publish/sentry.php +++ b/src/sentry/publish/sentry.php @@ -43,6 +43,7 @@ // @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#enable_metrics 'enable_metrics' => env('SENTRY_ENABLE_METRICS', true), 'enable_default_metrics' => env('SENTRY_ENABLE_DEFAULT_METRICS', true), + 'enable_command_metrics' => env('SENTRY_ENABLE_COMMAND_METRICS', true), 'metrics_interval' => (int) env('SENTRY_METRICS_INTERVAL', 10), 'logs_channel_level' => env('SENTRY_LOGS_CHANNEL_LEVEL', Sentry\Logs\LogLevel::debug()), diff --git a/src/sentry/src/Factory/ClientBuilderFactory.php b/src/sentry/src/Factory/ClientBuilderFactory.php index 30ebf72b2..c8ab118dd 100644 --- a/src/sentry/src/Factory/ClientBuilderFactory.php +++ b/src/sentry/src/Factory/ClientBuilderFactory.php @@ -32,6 +32,7 @@ class ClientBuilderFactory 'http_concurrent_limit', // deprecated, will be removed in v3.2 'logs_channel_level', 'enable_default_metrics', + 'enable_command_metrics', 'metrics_interval', 'transport_channel_size', 'transport_concurrent_limit', diff --git a/src/sentry/src/Feature.php b/src/sentry/src/Feature.php index dda8491c6..fa89298f1 100644 --- a/src/sentry/src/Feature.php +++ b/src/sentry/src/Feature.php @@ -45,6 +45,15 @@ public function isDefaultMetricsEnabled(bool $default = true): bool return (bool) $this->config->get('sentry.enable_default_metrics', $default); } + public function isCommandMetricsEnabled(bool $default = true): bool + { + if (! $this->isMetricsEnabled()) { + return false; + } + + return (bool) $this->config->get('sentry.enable_command_metrics', $default); + } + public function getMetricsInterval(int $default = 10): int { $interval = (int) $this->config->get('sentry.metrics_interval', $default); diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index db0e19643..93cf1f934 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -56,7 +56,7 @@ public function process(object $event): void Context::set(Constants::RUN_IN_COMMAND, true); - if (! $this->feature->isDefaultMetricsEnabled()) { + if (! $this->feature->isCommandMetricsEnabled()) { return; } From bdc47ab9e664f03c3a1d786a89c1ee68c2902f94 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:35:56 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=8F=98=E9=87=8F=E6=9B=BF=E4=BB=A3=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E7=AE=A1=E7=90=86=E5=91=BD=E4=BB=A4=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Constants.php | 2 +- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 5 ++--- src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sentry/src/Constants.php b/src/sentry/src/Constants.php index 33b344c37..cfa1d7469 100644 --- a/src/sentry/src/Constants.php +++ b/src/sentry/src/Constants.php @@ -39,5 +39,5 @@ class Constants public const TRACEPARENT = 'traceparent'; - public const RUN_IN_COMMAND = 'sentry.run_in_command'; + public static bool $runningInCommand = false; } diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index 93cf1f934..919bae4af 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -16,7 +16,6 @@ use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; use Hyperf\Command\Event\AfterExecute; use Hyperf\Command\Event\BeforeHandle; -use Hyperf\Context\Context; use Hyperf\Coordinator\CoordinatorManager; use Hyperf\Coordinator\Timer; use Hyperf\Engine\Coroutine; @@ -50,11 +49,11 @@ public function listen(): array public function process(object $event): void { if ($event instanceof AfterExecute) { - Context::destroy(Constants::RUN_IN_COMMAND); + Constants::$runningInCommand = false; return; } - Context::set(Constants::RUN_IN_COMMAND, true); + Constants::$runningInCommand = true; if (! $this->feature->isCommandMetricsEnabled()) { return; diff --git a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php index d14aa38fe..c83837310 100644 --- a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php +++ b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php @@ -11,11 +11,11 @@ namespace FriendsOfHyperf\Sentry\Metrics\Listener; +use FriendsOfHyperf\Sentry\Constants as SentryConstants; use FriendsOfHyperf\Sentry\Feature; use FriendsOfHyperf\Sentry\Metrics\CoroutineServerStats; use FriendsOfHyperf\Sentry\Metrics\Event\MetricFactoryReady; use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; -use Hyperf\Context\Context; use Hyperf\Coordinator\Constants; use Hyperf\Coordinator\CoordinatorManager; use Hyperf\Coordinator\Timer; @@ -86,7 +86,7 @@ public function process(object $event): void $serverStatsFactory = null; - if (! Context::get(\FriendsOfHyperf\Sentry\Constants::RUN_IN_COMMAND, false)) { + if (! SentryConstants::$runningInCommand) { if ($this->container->has(SwooleServer::class) && $server = $this->container->get(SwooleServer::class)) { if ($server instanceof SwooleServer) { $serverStatsFactory = fn (): array => $server->stats(); From a598089d37ec4cd0e9d63e169798c0fd334cbfd9 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:44:38 +0800 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4AfterExecute?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=8C=87=E6=A0=87=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Metrics/Listener/OnBeforeHandle.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index 919bae4af..b46a17a7e 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -14,7 +14,6 @@ use FriendsOfHyperf\Sentry\Constants; use FriendsOfHyperf\Sentry\Feature; use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; -use Hyperf\Command\Event\AfterExecute; use Hyperf\Command\Event\BeforeHandle; use Hyperf\Coordinator\CoordinatorManager; use Hyperf\Coordinator\Timer; @@ -39,26 +38,27 @@ public function listen(): array { return [ BeforeHandle::class, - AfterExecute::class, ]; } /** - * @param object|BeforeHandle|AfterExecute $event + * @param object|BeforeHandle $event */ public function process(object $event): void { - if ($event instanceof AfterExecute) { - Constants::$runningInCommand = false; + if (! $this->feature->isCommandMetricsEnabled()) { // Disabled return; } - Constants::$runningInCommand = true; - - if (! $this->feature->isCommandMetricsEnabled()) { + if ( + $event instanceof BeforeHandle + && ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Return when running in crontab + ) { return; } + Constants::$runningInCommand = true; + // The following metrics MUST be collected in worker. $metrics = [ 'memory_usage', From 4eb8bf2c03f3c6a39149802da5e369cc7a7ee80f Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:45:56 +0800 Subject: [PATCH 05/10] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=BB=A5=E6=9B=B4=E6=B8=85=E6=99=B0=E5=9C=B0=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E5=91=BD=E4=BB=A4=E8=87=AA=E5=8A=A8=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index b46a17a7e..0174c60da 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -52,7 +52,7 @@ public function process(object $event): void if ( $event instanceof BeforeHandle - && ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Return when running in crontab + && ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Only enable in the command with auto exit. ) { return; } From 31bc64ba8b8f195200aa70dae353fe1ceee014b1 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:46:57 +0800 Subject: [PATCH 06/10] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=8C=87=E6=A0=87=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E9=80=82=E5=BD=93=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E5=90=AF=E7=94=A8=E6=8C=87=E6=A0=87=E6=94=B6?= =?UTF-8?q?=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index 0174c60da..b5dc57bdc 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -46,13 +46,10 @@ public function listen(): array */ public function process(object $event): void { - if (! $this->feature->isCommandMetricsEnabled()) { // Disabled - return; - } - if ( - $event instanceof BeforeHandle - && ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Only enable in the command with auto exit. + ! $event instanceof BeforeHandle + || ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Only enable in the command with auto exit. + || ! $this->feature->isCommandMetricsEnabled() // Only enable in the command with command metrics enabled. ) { return; } From ba4ff3677d7ad3eda0143cbcb3229d4569324ffa Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:48:29 +0800 Subject: [PATCH 07/10] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=8C=87=E6=A0=87=E5=90=AF=E7=94=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E9=80=82=E5=BD=93=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E6=94=B6=E9=9B=86=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index b5dc57bdc..99c1e4bf5 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -49,13 +49,16 @@ public function process(object $event): void if ( ! $event instanceof BeforeHandle || ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Only enable in the command with auto exit. - || ! $this->feature->isCommandMetricsEnabled() // Only enable in the command with command metrics enabled. ) { return; } Constants::$runningInCommand = true; + if (! $this->feature->isCommandMetricsEnabled()) { + return; + } + // The following metrics MUST be collected in worker. $metrics = [ 'memory_usage', From 85423598258ad3f27fe91227210f3b762a4abb5f Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:49:03 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=8C=87=E6=A0=87=E5=90=AF=E7=94=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E9=80=82=E5=BD=93=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E6=94=B6=E9=9B=86=E9=BB=98=E8=AE=A4=E6=8C=87?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index 99c1e4bf5..654b6ad87 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -49,13 +49,14 @@ public function process(object $event): void if ( ! $event instanceof BeforeHandle || ! $event->getCommand()->getApplication()->isAutoExitEnabled() // Only enable in the command with auto exit. + || ! $this->feature->isCommandMetricsEnabled() ) { return; } Constants::$runningInCommand = true; - if (! $this->feature->isCommandMetricsEnabled()) { + if (! $this->feature->isDefaultMetricsEnabled()) { return; } From d5b219a5e2372d75be848a96b926b4117949f7e5 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:50:06 +0800 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E6=94=B6=E9=9B=86=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B0=86?= =?UTF-8?q?=E5=B7=A5=E4=BA=BA=E6=A0=87=E8=AF=86=E4=BB=8E'N/A'=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA'0'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnBeforeHandle.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php index 654b6ad87..995cd66f2 100644 --- a/src/sentry/src/Metrics/Listener/OnBeforeHandle.php +++ b/src/sentry/src/Metrics/Listener/OnBeforeHandle.php @@ -96,13 +96,13 @@ public function process(object $event): void metrics()->gauge( 'memory_usage', (float) memory_get_usage(), - ['worker' => 'N/A'], + ['worker' => '0'], Unit::byte() ); metrics()->gauge( 'memory_peak_usage', (float) memory_get_peak_usage(), - ['worker' => 'N/A'], + ['worker' => '0'], Unit::byte() ); }); From ac2f7ebf9319429202e7bd79f374b4fbdd8cd696 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:50:55 +0800 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=8C=87=E6=A0=87=E5=90=AF=E7=94=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E7=A6=81=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php index c83837310..153bb50fb 100644 --- a/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php +++ b/src/sentry/src/Metrics/Listener/OnMetricFactoryReady.php @@ -54,7 +54,7 @@ public function listen(): array */ public function process(object $event): void { - if ($this->feature->isDefaultMetricsEnabled()) { + if (! $this->feature->isDefaultMetricsEnabled()) { return; }