Skip to content

Commit 7604023

Browse files
authored
Refactor the console scheduling integration (#884)
* Rename the console scheduling integration * Move console integration to a feature class
1 parent e5f2154 commit 7604023

File tree

7 files changed

+461
-446
lines changed

7 files changed

+461
-446
lines changed

src/Sentry/Laravel/EventHandler.php

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Exception;
66
use Illuminate\Auth\Events as AuthEvents;
7-
use Illuminate\Console\Events as ConsoleEvents;
87
use Illuminate\Contracts\Auth\Authenticatable;
98
use Illuminate\Contracts\Container\BindingResolutionException;
109
use Illuminate\Contracts\Container\Container;
@@ -21,8 +20,6 @@
2120
use Sentry\Laravel\Tracing\Middleware;
2221
use Sentry\SentrySdk;
2322
use Sentry\State\Scope;
24-
use Symfony\Component\Console\Input\ArgvInput;
25-
use Symfony\Component\Console\Input\InputInterface;
2623

2724
class EventHandler
2825
{
@@ -35,8 +32,6 @@ class EventHandler
3532
LogEvents\MessageLogged::class => 'messageLogged',
3633
RoutingEvents\RouteMatched::class => 'routeMatched',
3734
DatabaseEvents\QueryExecuted::class => 'queryExecuted',
38-
ConsoleEvents\CommandStarting::class => 'commandStarting',
39-
ConsoleEvents\CommandFinished::class => 'commandFinished',
4035
];
4136

4237
/**
@@ -96,13 +91,6 @@ class EventHandler
9691
*/
9792
private $recordLaravelLogs;
9893

99-
/**
100-
* Indicates if we should add command info to the breadcrumbs.
101-
*
102-
* @var bool
103-
*/
104-
private $recordCommandInfo;
105-
10694
/**
10795
* Indicates if we should add tick info to the breadcrumbs.
10896
*
@@ -137,7 +125,6 @@ public function __construct(Container $container, array $config)
137125
$this->recordSqlQueries = ($config['breadcrumbs.sql_queries'] ?? $config['breadcrumbs']['sql_queries'] ?? true) === true;
138126
$this->recordSqlBindings = ($config['breadcrumbs.sql_bindings'] ?? $config['breadcrumbs']['sql_bindings'] ?? false) === true;
139127
$this->recordLaravelLogs = ($config['breadcrumbs.logs'] ?? $config['breadcrumbs']['logs'] ?? true) === true;
140-
$this->recordCommandInfo = ($config['breadcrumbs.command_info'] ?? $config['breadcrumbs']['command_info'] ?? true) === true;
141128
$this->recordOctaneTickInfo = ($config['breadcrumbs.octane_tick_info'] ?? $config['breadcrumbs']['octane_tick_info'] ?? true) === true;
142129
$this->recordOctaneTaskInfo = ($config['breadcrumbs.octane_task_info'] ?? $config['breadcrumbs']['octane_task_info'] ?? true) === true;
143130
}
@@ -316,68 +303,6 @@ private function configureUserScopeFromModel($authUser): void
316303
});
317304
}
318305

319-
protected function commandStartingHandler(ConsoleEvents\CommandStarting $event): void
320-
{
321-
if ($event->command) {
322-
Integration::configureScope(static function (Scope $scope) use ($event): void {
323-
$scope->setTag('command', $event->command);
324-
});
325-
326-
if (!$this->recordCommandInfo) {
327-
return;
328-
}
329-
330-
Integration::addBreadcrumb(new Breadcrumb(
331-
Breadcrumb::LEVEL_INFO,
332-
Breadcrumb::TYPE_DEFAULT,
333-
'artisan.command',
334-
'Starting Artisan command: ' . $event->command,
335-
[
336-
'input' => $this->extractConsoleCommandInput($event->input),
337-
]
338-
));
339-
}
340-
}
341-
342-
protected function commandFinishedHandler(ConsoleEvents\CommandFinished $event): void
343-
{
344-
if ($this->recordCommandInfo) {
345-
Integration::addBreadcrumb(new Breadcrumb(
346-
Breadcrumb::LEVEL_INFO,
347-
Breadcrumb::TYPE_DEFAULT,
348-
'artisan.command',
349-
'Finished Artisan command: ' . $event->command,
350-
[
351-
'exit' => $event->exitCode,
352-
'input' => $this->extractConsoleCommandInput($event->input),
353-
]
354-
));
355-
}
356-
357-
// Flush any and all events that were possibly generated by the command
358-
Integration::flushEvents();
359-
360-
Integration::configureScope(static function (Scope $scope): void {
361-
$scope->removeTag('command');
362-
});
363-
}
364-
365-
/**
366-
* Extract the command input arguments if possible.
367-
*
368-
* @param \Symfony\Component\Console\Input\InputInterface|null $input
369-
*
370-
* @return string|null
371-
*/
372-
private function extractConsoleCommandInput(?InputInterface $input): ?string
373-
{
374-
if ($input instanceof ArgvInput) {
375-
return (string)$input;
376-
}
377-
378-
return null;
379-
}
380-
381306
protected function octaneRequestReceivedHandler(Octane\RequestReceived $event): void
382307
{
383308
$this->prepareScopeForOctane();

0 commit comments

Comments
 (0)