Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breadcrumbs.queue_info also controlling command info #350

Merged
merged 5 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Add `send_default_pii` option by default to published config file (#340)
- Update `.gitattributes` to exclude more files from dist release (#341)
- 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 @@ -450,7 +458,7 @@ protected function commandStartingHandler(CommandStarting $event)
$scope->setTag('command', $event->command);
});

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

Expand All @@ -473,19 +481,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