Skip to content

Commit e31457b

Browse files
committed
Resolve name for all queued job types
1 parent f838c9b commit e31457b

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
class ConsoleSchedulingIntegration extends Feature
2828
{
29-
use TracksPushedScopesAndSpans {
30-
pushScope as private pushScopeTrait;
31-
}
29+
use TracksPushedScopesAndSpans;
3230

3331
/**
3432
* @var string|null
@@ -142,12 +140,19 @@ public function handleScheduledTaskStarting(ScheduledTaskStarting $event): void
142140
return;
143141
}
144142

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+
145150
$context = TransactionContext::make()
146-
->setName($event->task->description)
151+
->setName($name)
147152
->setSource(TransactionSource::task())
148-
->setOp('console.command')
153+
->setOp('console.command.scheduled')
149154
->setStartTimestamp(microtime(true));
150-
155+
151156
$transaction = SentrySdk::getCurrentHub()->startTransaction($context);
152157

153158
$this->pushSpan($transaction);
@@ -293,6 +298,18 @@ private function makeSlugForScheduled(SchedulingEvent $scheduled): string
293298
return "scheduled_{$generatedSlug}";
294299
}
295300

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+
296313
private function resolveCache(): Repository
297314
{
298315
return $this->container()->make(Cache::class)->store($this->cacheStore);

0 commit comments

Comments
 (0)