diff --git a/src/ListensForStorageOpportunities.php b/src/ListensForStorageOpportunities.php index 406ab17ef..382e74411 100644 --- a/src/ListensForStorageOpportunities.php +++ b/src/ListensForStorageOpportunities.php @@ -6,6 +6,8 @@ use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessing; +use Laravel\Octane\Events\RequestReceived; +use Laravel\Octane\Events\RequestTerminated; use Laravel\Telescope\Contracts\EntriesRepository; trait ListensForStorageOpportunities @@ -25,11 +27,30 @@ trait ListensForStorageOpportunities */ public static function listenForStorageOpportunities($app) { + static::manageRecordingStateForOctane($app); static::storeEntriesBeforeTermination($app); - static::storeEntriesAfterWorkerLoop($app); } + /** + * Manage starting and stopping the recording state for Octane. + * + * @param \Illuminate\Foundation\Application $app + * @return void + */ + protected static function manageRecordingStateForOctane($app) + { + $app['events']->listen(RequestReceived::class, function ($event) { + if (static::requestIsToApprovedUri($event->request)) { + static::startRecording(); + } + }); + + $app['events']->listen(RequestTerminated::class, function ($event) { + static::stopRecording(); + }); + } + /** * Store the entries in queue before the application termination. * diff --git a/src/Telescope.php b/src/Telescope.php index 7e3d3e98c..406480432 100644 --- a/src/Telescope.php +++ b/src/Telescope.php @@ -144,13 +144,25 @@ public static function start($app) static::registerMailableTagExtractor(); - if (static::runningApprovedArtisanCommand($app) || - static::handlingApprovedRequest($app) + if (! static::runningWithinOctane($app) && + (static::runningApprovedArtisanCommand($app) || + static::handlingApprovedRequest($app)) ) { static::startRecording(); } } + /** + * Determine if Telescope is running within Octane. + * + * @param \Illuminate\Foundation\Application $app + * @return bool + */ + protected static function runningWithinOctane($app) + { + return isset($_SERVER['LARAVEL_OCTANE']); + } + /** * Determine if the application is running an approved command. * @@ -190,11 +202,22 @@ protected static function handlingApprovedRequest($app) return false; } + return static::requestIsToApprovedUri($app['request']); + } + + /** + * Determine if the request is to an approved URI. + * + * @param \Illuminate\Http\Request $request + * @return bool + */ + protected static function requestIsToApprovedUri($request) + { if (! empty($only = config('telescope.only_paths', []))) { - return $app['request']->is($only); + return $request->is($only); } - return ! $app['request']->is( + return ! $request->is( array_merge([ config('telescope.path').'*', 'telescope-api*', diff --git a/src/Watchers/EventWatcher.php b/src/Watchers/EventWatcher.php index d8a9b6642..d95d61ced 100644 --- a/src/Watchers/EventWatcher.php +++ b/src/Watchers/EventWatcher.php @@ -129,7 +129,7 @@ protected function shouldIgnore($eventName) protected function eventIsFiredByTheFramework($eventName) { return Str::is( - ['Illuminate\*', 'eloquent*', 'bootstrapped*', 'bootstrapping*', 'creating*', 'composing*'], + ['Illuminate\*', 'Laravel\Octane\*', 'eloquent*', 'bootstrapped*', 'bootstrapping*', 'creating*', 'composing*'], $eventName ); }