|
26 | 26 |
|
27 | 27 | class ConsoleSchedulingIntegration extends Feature |
28 | 28 | { |
29 | | - use TracksPushedScopesAndSpans { |
30 | | - pushScope as private pushScopeTrait; |
31 | | - } |
| 29 | + use TracksPushedScopesAndSpans; |
32 | 30 |
|
33 | 31 | /** |
34 | 32 | * @var string|null |
@@ -142,12 +140,19 @@ public function handleScheduledTaskStarting(ScheduledTaskStarting $event): void |
142 | 140 | return; |
143 | 141 | } |
144 | 142 |
|
| 143 | + // When scheduling a command class the command name will be the most descriptive |
| 144 | + // When a job is scheduled the command name is `null` and the job class name (or display name) is set as the description |
| 145 | + // When a closure is scheduled both the command name and description are `null` |
| 146 | + $name = $this->getCommandNameForScheduled($event->task) ?? $event->task->description ?? 'Closure'; |
| 147 | + |
| 148 | + dump($name); |
| 149 | + |
145 | 150 | $context = TransactionContext::make() |
146 | | - ->setName($event->task->description) |
| 151 | + ->setName($name) |
147 | 152 | ->setSource(TransactionSource::task()) |
148 | | - ->setOp('console.command') |
| 153 | + ->setOp('console.command.scheduled') |
149 | 154 | ->setStartTimestamp(microtime(true)); |
150 | | - |
| 155 | + |
151 | 156 | $transaction = SentrySdk::getCurrentHub()->startTransaction($context); |
152 | 157 |
|
153 | 158 | $this->pushSpan($transaction); |
@@ -293,6 +298,18 @@ private function makeSlugForScheduled(SchedulingEvent $scheduled): string |
293 | 298 | return "scheduled_{$generatedSlug}"; |
294 | 299 | } |
295 | 300 |
|
| 301 | + private function getCommandNameForScheduled(SchedulingEvent $scheduled): ?string |
| 302 | + { |
| 303 | + if (!$scheduled->command) { |
| 304 | + return null; |
| 305 | + } |
| 306 | + |
| 307 | + // The command string always starts with the PHP binary, so we remove it since it's not relevant to the slug |
| 308 | + return trim( |
| 309 | + Str::after($scheduled->command, ConsoleApplication::phpBinary() . ' ' . ConsoleApplication::artisanBinary()) |
| 310 | + ); |
| 311 | + } |
| 312 | + |
296 | 313 | private function resolveCache(): Repository |
297 | 314 | { |
298 | 315 | return $this->container()->make(Cache::class)->store($this->cacheStore); |
|
0 commit comments