From d0c1d06eddb46c552aa8dc5d3291b6e7cb47c94b Mon Sep 17 00:00:00 2001 From: billpyang Date: Mon, 15 Sep 2025 16:51:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:octane=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=AF=BC?= =?UTF-8?q?=E5=87=BAmetric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Facades/Metric.php | 1 + src/Handlers/RequestTerminatedHandler.php | 2 ++ src/Support/Metric.php | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/src/Facades/Metric.php b/src/Facades/Metric.php index feae3b6..9bd51df 100644 --- a/src/Facades/Metric.php +++ b/src/Facades/Metric.php @@ -14,6 +14,7 @@ * @method static \OpenTelemetry\API\Metrics\HistogramInterface histogram(string $name, ?string $unit = null, ?string $description = null, array $advisories = []) * @method static \OpenTelemetry\API\Metrics\GaugeInterface gauge(string $name, ?string $unit = null, ?string $description = null, array $advisories = []) * @method static \OpenTelemetry\API\Metrics\ObservableGaugeInterface observableGauge(string $name, ?string $unit = null, ?string $description = null, array|callable $advisories = [], callable ...$callbacks) + * @method static void flush() * * @see \Overtrue\LaravelOpenTelemetry\Support\Metric */ diff --git a/src/Handlers/RequestTerminatedHandler.php b/src/Handlers/RequestTerminatedHandler.php index b2d7b64..8cd7687 100644 --- a/src/Handlers/RequestTerminatedHandler.php +++ b/src/Handlers/RequestTerminatedHandler.php @@ -6,6 +6,7 @@ use Laravel\Octane\Events\RequestTerminated; use Overtrue\LaravelOpenTelemetry\Facades\Measure; +use Overtrue\LaravelOpenTelemetry\Facades\Metric; class RequestTerminatedHandler { @@ -16,5 +17,6 @@ public function handle(RequestTerminated $event): void { // In Octane mode, we need to force flush the tracer provider. Measure::flush(); + Metric::flush(); } } diff --git a/src/Support/Metric.php b/src/Support/Metric.php index 14e1ffe..c3f28d5 100644 --- a/src/Support/Metric.php +++ b/src/Support/Metric.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Facades\Log; +use OpenTelemetry\API\Globals; use OpenTelemetry\API\Metrics\CounterInterface; use OpenTelemetry\API\Metrics\GaugeInterface; use OpenTelemetry\API\Metrics\HistogramInterface; @@ -39,6 +40,14 @@ public function isEnabled(): bool return self::$enabled; } + /** + * Force flush (for Octane mode) + */ + public function flush(): void + { + Globals::meterProvider()?->forceFlush(); + } + // ======================= Core OpenTelemetry API ======================= /**