Skip to content

Commit ccf55af

Browse files
authored
Fix breadcrumbs.queue_info also controlling command info (#350)
1 parent cc7ae9a commit ccf55af

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Add `send_default_pii` option by default to published config file (#340)
66
- Update `.gitattributes` to exclude more files from dist release (#341)
77
- Ignore log breadcrumbs when `null` is the message logged (#345)
8+
- Fix `breadcrumbs.queue_info` controlling breadcrumbs generated by commands (#350)
9+
- Add `breadcrumbs.command_info` to control breadcrumbs generated by commands (#350)
810
- Fixed scope data in queue jobs being lost in some cases (#351)
911

1012
## 1.7.1

config/sentry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
// Capture queue job information in breadcrumbs
2121
'queue_info' => true,
22+
23+
// Capture command information in breadcrumbs
24+
'command_info' => true,
2225
],
2326

2427
// @see: https://docs.sentry.io/error-reporting/configuration/?platform=php#send-default-pii

src/Sentry/Laravel/EventHandler.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class EventHandler
9999
*/
100100
private $recordQueueInfo;
101101

102+
/**
103+
* Indicates if we should we add command info to the breadcrumbs.
104+
*
105+
* @var bool
106+
*/
107+
private $recordCommandInfo;
108+
102109
/**
103110
* Indicates if we pushed a scope for the queue.
104111
*
@@ -119,6 +126,7 @@ public function __construct(Dispatcher $events, array $config)
119126
$this->recordSqlBindings = ($config['breadcrumbs.sql_bindings'] ?? $config['breadcrumbs']['sql_bindings'] ?? false) === true;
120127
$this->recordLaravelLogs = ($config['breadcrumbs.logs'] ?? $config['breadcrumbs']['logs'] ?? true) === true;
121128
$this->recordQueueInfo = ($config['breadcrumbs.queue_info'] ?? $config['breadcrumbs']['queue_info'] ?? true) === true;
129+
$this->recordCommandInfo = ($config['breadcrumbs.command_info'] ?? $config['breadcrumbs']['command_info'] ?? true) === true;
122130
}
123131

124132
/**
@@ -457,7 +465,7 @@ protected function commandStartingHandler(CommandStarting $event)
457465
$scope->setTag('command', $event->command);
458466
});
459467

460-
if (!$this->recordQueueInfo) {
468+
if (!$this->recordCommandInfo) {
461469
return;
462470
}
463471

@@ -480,19 +488,21 @@ protected function commandStartingHandler(CommandStarting $event)
480488
*/
481489
protected function commandFinishedHandler(CommandFinished $event)
482490
{
483-
Integration::addBreadcrumb(new Breadcrumb(
484-
Breadcrumb::LEVEL_INFO,
485-
Breadcrumb::TYPE_DEFAULT,
486-
'artisan.command',
487-
'Finished Artisan command: ' . $event->command,
488-
array_merge([
489-
'exit' => $event->exitCode,
490-
], method_exists($event->input, '__toString') ? [
491-
'input' => (string)$event->input,
492-
] : [])
493-
));
491+
if ($this->recordCommandInfo) {
492+
Integration::addBreadcrumb(new Breadcrumb(
493+
Breadcrumb::LEVEL_INFO,
494+
Breadcrumb::TYPE_DEFAULT,
495+
'artisan.command',
496+
'Finished Artisan command: ' . $event->command,
497+
array_merge([
498+
'exit' => $event->exitCode,
499+
], method_exists($event->input, '__toString') ? [
500+
'input' => (string)$event->input,
501+
] : [])
502+
));
503+
}
494504

495-
Integration::configureScope(static function (Scope $scope) use ($event): void {
505+
Integration::configureScope(static function (Scope $scope): void {
496506
$scope->setTag('command', '');
497507
});
498508

test/Sentry/QueueInfoInBreadcrumbsTest.php renamed to test/Sentry/CommandInfoInBreadcrumbsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
use Symfony\Component\Console\Input\ArrayInput;
77
use Symfony\Component\Console\Output\BufferedOutput;
88

9-
class QueueInfoInBreadcrumbsTest extends SentryLaravelTestCase
9+
class CommandInfoInBreadcrumbsTest extends SentryLaravelTestCase
1010
{
11-
public function testQueueInfoAreRecordedWhenEnabled()
11+
public function testCommandInfoAreRecordedWhenEnabled()
1212
{
1313
if ($this->shouldSkip()) {
1414
$this->markTestSkipped('Laravel version <5.5 does not contain the events tested.');
1515
}
1616

1717
$this->resetApplicationWithConfig([
18-
'sentry.breadcrumbs.queue_info' => true,
18+
'sentry.breadcrumbs.command_info' => true,
1919
]);
2020

21-
$this->assertTrue($this->app['config']->get('sentry.breadcrumbs.queue_info'));
21+
$this->assertTrue($this->app['config']->get('sentry.breadcrumbs.command_info'));
2222

2323
$this->dispatchCommandStartEvent();
2424

@@ -28,17 +28,17 @@ public function testQueueInfoAreRecordedWhenEnabled()
2828
$this->assertEquals('--foo=bar', $lastBreadcrumb->getMetadata()['input']);
2929
}
3030

31-
public function testQueueInfoAreRecordedWhenDisabled()
31+
public function testCommandInfoAreRecordedWhenDisabled()
3232
{
3333
if ($this->shouldSkip()) {
3434
$this->markTestSkipped('Laravel version <5.5 does not contain the events tested.');
3535
}
3636

3737
$this->resetApplicationWithConfig([
38-
'sentry.breadcrumbs.queue_info' => false,
38+
'sentry.breadcrumbs.command_info' => false,
3939
]);
4040

41-
$this->assertFalse($this->app['config']->get('sentry.breadcrumbs.queue_info'));
41+
$this->assertFalse($this->app['config']->get('sentry.breadcrumbs.command_info'));
4242

4343
$this->dispatchCommandStartEvent();
4444

0 commit comments

Comments
 (0)