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

#22047: Magento CRON Job Names are missing in NewRelic: Transactions FIX #22061

Closed
Changes from all 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
36 changes: 36 additions & 0 deletions app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class ProcessCronQueueObserver implements ObserverInterface
*/
private $statProfiler;

/**
* Key and Value Array of Cron Job Names
*/
protected const LIST_CRON_NAME = [];

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Magento\Cron\Model\ScheduleFactory $scheduleFactory
Expand Down Expand Up @@ -218,6 +223,11 @@ function ($a, $b) {

$phpPath = $this->phpExecutableFinder->find() ?: 'php';

// End previous NewRelic Transaction to track Cron Job Traces
if (extension_loaded('newrelic')) {
newrelic_end_transaction(true);
}

foreach ($jobGroupsRoot as $groupId => $jobsRoot) {
if (!$this->isGroupInFilter($groupId)) {
continue;
Expand Down Expand Up @@ -734,6 +744,12 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)

try {
if ($schedule->tryLockJob()) {
if (extension_loaded('newrelic')) {
//Get Job Name after Name Changes
$jobName = $this->changeCronName($schedule->getJobCode());
newrelic_start_transaction(ini_get('newrelic.appname'));
newrelic_name_transaction($jobName);
}
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
}
} catch (\Exception $e) {
Expand All @@ -742,6 +758,10 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)
if ($schedule->getStatus() === Schedule::STATUS_SUCCESS) {
$procesedJobs[$schedule->getJobCode()] = true;
}

if (extension_loaded('newrelic')) {
newrelic_end_transaction();
}
$schedule->save();
}
}
Expand All @@ -765,4 +785,20 @@ private function processError(\Magento\Cron\Model\Schedule $schedule, \Exception
$this->logger->info($schedule->getMessages());
}
}

/**
* Get Cron Name for proper CRON Job Traces Tracking
*
* @param string $keyCronName
*
* @return mixed
*/
public static function changeCronName($keyCronName)
{
$cronNameMagento = self::LIST_CRON_NAME;
if (isset($cronNameMagento[$keyCronName])) {
return $cronNameMagento[$keyCronName];
}
return $keyCronName;
}
}