Skip to content

Commit 973a0f1

Browse files
authored
Add tag with name of console command
Listen for the `CommandStarting` event and add a tag with the name of the console command. This makes it easy to know which console command has the error. Note: I did not typehint `ComandStarting` in `commandStartingHandler` because then I think it would only work on Laravel >=5.5 and based on the documentation this package supports Laravel 5.*. I'm surprised that the typehint of `MessageLogged` on `messageLoggedHandler` does not cause issues for people trying to use older versions of Laravel since `MessageLogged` was not added until Laravel 5.4.
1 parent b4a19e8 commit 973a0f1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Sentry/SentryLaravel/SentryLaravelEventHandler.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class SentryLaravelEventHandler
2727

2828
'illuminate.log' => 'log', // Until Laravel 5.3
2929
'Illuminate\Log\Events\MessageLogged' => 'messageLogged', // Since Laravel 5.4
30+
31+
'Illuminate\Console\Events\CommandStarting' => 'commandStarting', // Since Laravel 5.5
3032
);
3133

3234
/**
@@ -223,6 +225,18 @@ protected function messageLoggedHandler(MessageLogged $logEntry)
223225
));
224226
}
225227

228+
/**
229+
* Since Laravel 5.5
230+
*
231+
* @param Illuminate\Console\Events\CommandStarting $event
232+
*/
233+
protected function commandStartingHandler($event)
234+
{
235+
$this->client->tags_context(array(
236+
'command' => $event->command,
237+
));
238+
}
239+
226240
/**
227241
* Since Laravel 5.3
228242
*

0 commit comments

Comments
 (0)