Skip to content

Commit

Permalink
Fix breadcrumbs.queue_info also controlling command info (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive authored Jun 2, 2020
1 parent cc7ae9a commit ccf55af
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Add `send_default_pii` option by default to published config file (#340)
- Update `.gitattributes` to exclude more files from dist release (#341)
- Ignore log breadcrumbs when `null` is the message logged (#345)
- Fix `breadcrumbs.queue_info` controlling breadcrumbs generated by commands (#350)
- Add `breadcrumbs.command_info` to control breadcrumbs generated by commands (#350)
- Fixed scope data in queue jobs being lost in some cases (#351)

## 1.7.1
Expand Down
3 changes: 3 additions & 0 deletions config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

// Capture queue job information in breadcrumbs
'queue_info' => true,

// Capture command information in breadcrumbs
'command_info' => true,
],

// @see: https://docs.sentry.io/error-reporting/configuration/?platform=php#send-default-pii
Expand Down
36 changes: 23 additions & 13 deletions src/Sentry/Laravel/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class EventHandler
*/
private $recordQueueInfo;

/**
* Indicates if we should we add command info to the breadcrumbs.
*
* @var bool
*/
private $recordCommandInfo;

/**
* Indicates if we pushed a scope for the queue.
*
Expand All @@ -119,6 +126,7 @@ public function __construct(Dispatcher $events, array $config)
$this->recordSqlBindings = ($config['breadcrumbs.sql_bindings'] ?? $config['breadcrumbs']['sql_bindings'] ?? false) === true;
$this->recordLaravelLogs = ($config['breadcrumbs.logs'] ?? $config['breadcrumbs']['logs'] ?? true) === true;
$this->recordQueueInfo = ($config['breadcrumbs.queue_info'] ?? $config['breadcrumbs']['queue_info'] ?? true) === true;
$this->recordCommandInfo = ($config['breadcrumbs.command_info'] ?? $config['breadcrumbs']['command_info'] ?? true) === true;
}

/**
Expand Down Expand Up @@ -457,7 +465,7 @@ protected function commandStartingHandler(CommandStarting $event)
$scope->setTag('command', $event->command);
});

if (!$this->recordQueueInfo) {
if (!$this->recordCommandInfo) {
return;
}

Expand All @@ -480,19 +488,21 @@ protected function commandStartingHandler(CommandStarting $event)
*/
protected function commandFinishedHandler(CommandFinished $event)
{
Integration::addBreadcrumb(new Breadcrumb(
Breadcrumb::LEVEL_INFO,
Breadcrumb::TYPE_DEFAULT,
'artisan.command',
'Finished Artisan command: ' . $event->command,
array_merge([
'exit' => $event->exitCode,
], method_exists($event->input, '__toString') ? [
'input' => (string)$event->input,
] : [])
));
if ($this->recordCommandInfo) {
Integration::addBreadcrumb(new Breadcrumb(
Breadcrumb::LEVEL_INFO,
Breadcrumb::TYPE_DEFAULT,
'artisan.command',
'Finished Artisan command: ' . $event->command,
array_merge([
'exit' => $event->exitCode,
], method_exists($event->input, '__toString') ? [
'input' => (string)$event->input,
] : [])
));
}

Integration::configureScope(static function (Scope $scope) use ($event): void {
Integration::configureScope(static function (Scope $scope): void {
$scope->setTag('command', '');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

class QueueInfoInBreadcrumbsTest extends SentryLaravelTestCase
class CommandInfoInBreadcrumbsTest extends SentryLaravelTestCase
{
public function testQueueInfoAreRecordedWhenEnabled()
public function testCommandInfoAreRecordedWhenEnabled()
{
if ($this->shouldSkip()) {
$this->markTestSkipped('Laravel version <5.5 does not contain the events tested.');
}

$this->resetApplicationWithConfig([
'sentry.breadcrumbs.queue_info' => true,
'sentry.breadcrumbs.command_info' => true,
]);

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

$this->dispatchCommandStartEvent();

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

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

$this->resetApplicationWithConfig([
'sentry.breadcrumbs.queue_info' => false,
'sentry.breadcrumbs.command_info' => false,
]);

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

$this->dispatchCommandStartEvent();

Expand Down

0 comments on commit ccf55af

Please sign in to comment.