|
3 | 3 | namespace Sentry\Laravel\Console;
|
4 | 4 |
|
5 | 5 | use Exception;
|
| 6 | +use Sentry\Event; |
6 | 7 | use Illuminate\Console\Command;
|
7 | 8 | use Illuminate\Support\Str;
|
8 | 9 | use Psr\Log\AbstractLogger;
|
|
18 | 19 |
|
19 | 20 | class TestCommand extends Command
|
20 | 21 | {
|
21 |
| - /** |
22 |
| - * The name and signature of the console command. |
23 |
| - * |
24 |
| - * @var string |
25 |
| - */ |
26 | 22 | protected $signature = 'sentry:test {--transaction} {--dsn=}';
|
27 |
| - |
28 |
| - /** |
29 |
| - * The console command description. |
30 |
| - * |
31 |
| - * @var string |
32 |
| - */ |
33 | 23 | protected $description = 'Generate a test event and send it to Sentry';
|
34 | 24 |
|
35 | 25 | /**
|
@@ -90,10 +80,31 @@ public function handle(): int
|
90 | 80 |
|
91 | 81 | $options = [
|
92 | 82 | 'dsn' => $dsn,
|
| 83 | + 'before_send' => static function (Event $event): ?Event { |
| 84 | + foreach ($event->getExceptions() as $exception) { |
| 85 | + $stacktrace = $exception->getStacktrace(); |
| 86 | + |
| 87 | + if ($stacktrace === null) { |
| 88 | + continue; |
| 89 | + } |
| 90 | + |
| 91 | + foreach ($stacktrace->getFrames() as $frame) { |
| 92 | + if (str_starts_with($frame->getAbsoluteFilePath(), __DIR__)) { |
| 93 | + $frame->setIsInApp(true); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + return $event; |
| 99 | + }, |
| 100 | + // We include this file as "in-app" so that the events generated have something to show |
| 101 | + 'in_app_include' => [__DIR__], |
| 102 | + 'in_app_exclude' => [base_path('artisan'), base_path('vendor')], |
93 | 103 | 'traces_sample_rate' => 1.0,
|
94 | 104 | ];
|
95 | 105 |
|
96 | 106 | if ($laravelClient !== null) {
|
| 107 | + // Some options are taken from the client as configured by the user |
97 | 108 | $options = array_merge($options, [
|
98 | 109 | 'release' => $laravelClient->getOptions()->getRelease(),
|
99 | 110 | 'environment' => $laravelClient->getOptions()->getEnvironment(),
|
@@ -143,6 +154,7 @@ public function log($level, $message, array $context = []): void
|
143 | 154 | }
|
144 | 155 | });
|
145 | 156 |
|
| 157 | + // We create a new Hub and Client to prevent user configuration from affecting the test command |
146 | 158 | $hub = new Hub($clientBuilder->getClient());
|
147 | 159 |
|
148 | 160 | $this->info('Sending test event...');
|
@@ -199,14 +211,9 @@ public function log($level, $message, array $context = []): void
|
199 | 211 | }
|
200 | 212 |
|
201 | 213 | /**
|
202 |
| - * Generate a test exception to send to Sentry. |
203 |
| - * |
204 |
| - * @param $command |
205 |
| - * @param $arg |
206 |
| - * |
207 |
| - * @return \Exception |
| 214 | + * Generate an example exception to send to Sentry. |
208 | 215 | */
|
209 |
| - protected function generateTestException($command, $arg): Exception |
| 216 | + protected function generateTestException(string $command, array $arg): Exception |
210 | 217 | {
|
211 | 218 | // Do something silly
|
212 | 219 | try {
|
|
0 commit comments