Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Facades/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Handlers/RequestTerminatedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laravel\Octane\Events\RequestTerminated;
use Overtrue\LaravelOpenTelemetry\Facades\Measure;
use Overtrue\LaravelOpenTelemetry\Facades\Metric;

class RequestTerminatedHandler
{
Expand All @@ -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();
}
}
9 changes: 9 additions & 0 deletions src/Support/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =======================

/**
Expand Down