Skip to content

Commit f650e3f

Browse files
committed
ACP2E-3067: Magento discards most New Relic cron transactions #34108
1 parent 203c2f7 commit f650e3f

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class NewRelicWrapper
1616
{
17+
private const NEWRELIC_APPNAME = 'newrelic.appname';
18+
1719
/**
1820
* Wrapper for 'newrelic_add_custom_parameter' function
1921
*
@@ -69,6 +71,19 @@ public function setTransactionName(string $transactionName): void
6971
}
7072
}
7173

74+
/**
75+
* Wrapper to start background transaction
76+
*
77+
* @return void
78+
*/
79+
public function startBackgroundTransaction()
80+
{
81+
if ($this->isExtensionInstalled()) {
82+
newrelic_start_transaction(ini_get(self::NEWRELIC_APPNAME));
83+
newrelic_background_job();
84+
}
85+
}
86+
7287
/**
7388
* Wrapper for 'newrelic_end_transaction'
7489
*

app/code/Magento/NewRelicReporting/Plugin/StatPlugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function beforeStart(Stat $schedule, ...$args): array
6464
$timerName = current($args);
6565

6666
if ($this->isCronJob($timerName)) {
67+
$this->newRelicWrapper->startBackgroundTransaction();
6768
$this->newRelicWrapper->setTransactionName(
6869
sprintf('Cron %s', $timerName)
6970
);

app/code/Magento/NewRelicReporting/Test/Unit/Plugin/StatPluginTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ protected function setUp(): void
5555
*/
5656
public function testNewRelicTransactionNameIsNotSetIfNotCronjobPattern()
5757
{
58+
$this->newRelicWrapperMock
59+
->expects($this->never())
60+
->method('startBackgroundTransaction');
5861
$this->newRelicWrapperMock
5962
->expects($this->never())
6063
->method('setTransactionName');
@@ -71,6 +74,9 @@ public function testNewRelicTransactionNameIsNotSetIfNotCronjobPattern()
7174
*/
7275
public function testNewRelicTransactionNameIsSetForCronjobNamePattern()
7376
{
77+
$this->newRelicWrapperMock
78+
->expects($this->once())
79+
->method('startBackgroundTransaction');
7480
$this->newRelicWrapperMock
7581
->expects($this->once())
7682
->method('setTransactionName');
@@ -90,7 +96,7 @@ private function getNewRelicWrapperMock(): NewRelicWrapper
9096
if (null === $this->newRelicWrapperMock) {
9197
$this->newRelicWrapperMock = $this->getMockBuilder(NewRelicWrapper::class)
9298
->disableOriginalConstructor()
93-
->setMethods(['setTransactionName', 'endTransaction'])
99+
->setMethods(['setTransactionName', 'endTransaction', 'startBackgroundTransaction'])
94100
->getMock();
95101
}
96102

app/code/Magento/NewRelicReporting/etc/di.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@
4646
<type name="Magento\Framework\Profiler\Driver\Standard\Stat">
4747
<plugin name="newrelic-describe-cronjobs" type="Magento\NewRelicReporting\Plugin\StatPlugin"/>
4848
</type>
49-
<type name="Magento\NewRelicReporting\Plugin\CommandPlugin">
50-
<arguments>
51-
<argument name="skipCommands" xsi:type="array">
52-
<item xsi:type="boolean" name="cron:run">true</item>
53-
<item xsi:type="boolean" name="server:run">true</item>
54-
</argument>
55-
</arguments>
56-
</type>
5749
<type name="Magento\NewRelicReporting\Model\Apm\Deployments">
5850
<arguments>
5951
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Json</argument>

0 commit comments

Comments
 (0)