Skip to content

Commit 4bc01ab

Browse files
authored
Merge branch 'master' into 3.x
2 parents efecb3e + acbf236 commit 4bc01ab

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
- Add tracing span for Laravel HTTP client requests (#585)
2121
- Simplify Sentry meta tag retrieval, by adding `Sentry\Laravel\Integration::sentryMeta()` (#586)
2222

23+
## 2.14.2
24+
25+
- Fix extracting command input resulting in errors when calling Artisan commands programatically with `null` as an argument value (#589)
26+
2327
## 2.14.1
2428

2529
- Fix not setting the correct SDK ID and version when running the `sentry:test` command (#582)

src/Sentry/Laravel/EventHandler.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use Sentry\Breadcrumb;
2323
use Sentry\SentrySdk;
2424
use Sentry\State\Scope;
25+
use Symfony\Component\Console\Input\ArgvInput;
26+
use Symfony\Component\Console\Input\InputInterface;
2527

2628
class EventHandler
2729
{
@@ -443,9 +445,9 @@ protected function commandStartingHandler(ConsoleEvents\CommandStarting $event):
443445
Breadcrumb::TYPE_DEFAULT,
444446
'artisan.command',
445447
'Starting Artisan command: ' . $event->command,
446-
method_exists($event->input, '__toString') ? [
447-
'input' => (string)$event->input,
448-
] : []
448+
[
449+
'input' => $this->extractConsoleCommandInput($event->input),
450+
]
449451
));
450452
}
451453
}
@@ -458,20 +460,35 @@ protected function commandFinishedHandler(ConsoleEvents\CommandFinished $event):
458460
Breadcrumb::TYPE_DEFAULT,
459461
'artisan.command',
460462
'Finished Artisan command: ' . $event->command,
461-
array_merge([
463+
[
462464
'exit' => $event->exitCode,
463-
], method_exists($event->input, '__toString') ? [
464-
'input' => (string)$event->input,
465-
] : [])
465+
'input' => $this->extractConsoleCommandInput($event->input),
466+
]
466467
));
467468
}
468469

470+
// Flush any and all events that were possibly generated by the command
471+
Integration::flushEvents();
472+
469473
Integration::configureScope(static function (Scope $scope): void {
470-
$scope->setTag('command', '');
474+
$scope->removeTag('command');
471475
});
476+
}
472477

473-
// Flush any and all events that were possibly generated by the command
474-
Integration::flushEvents();
478+
/**
479+
* Extract the command input arguments if possible.
480+
*
481+
* @param \Symfony\Component\Console\Input\InputInterface|null $input
482+
*
483+
* @return string|null
484+
*/
485+
private function extractConsoleCommandInput(?InputInterface $input): ?string
486+
{
487+
if ($input instanceof ArgvInput) {
488+
return (string)$input;
489+
}
490+
491+
return null;
475492
}
476493

477494
protected function octaneRequestReceivedHandler(Octane\RequestReceived $event): void

src/Sentry/Laravel/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
final class Version
66
{
77
public const SDK_IDENTIFIER = 'sentry.php.laravel';
8-
public const SDK_VERSION = '2.14.1';
8+
public const SDK_VERSION = '2.14.2';
99
}

test/Sentry/CommandInfoInBreadcrumbsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Sentry\Laravel\Tests;
44

55
use Illuminate\Console\Events\CommandStarting;
6-
use Symfony\Component\Console\Input\ArrayInput;
6+
use Symfony\Component\Console\Input\ArgvInput;
77
use Symfony\Component\Console\Output\BufferedOutput;
88

99
class CommandInfoInBreadcrumbsTest extends SentryLaravelTestCase
@@ -47,7 +47,7 @@ private function dispatchCommandStartEvent()
4747
CommandStarting::class,
4848
new CommandStarting(
4949
'test:command',
50-
new ArrayInput(['--foo' => 'bar']),
50+
new ArgvInput(['artisan', '--foo=bar']),
5151
new BufferedOutput()
5252
)
5353
);

0 commit comments

Comments
 (0)