Skip to content

Commit 76f8b02

Browse files
committed
Merge branch 'ACP2E-3067' of https://github.com/adobe-commerce-tier-4/magento2ce into T4-PR-06-14-2024
2 parents ab5947b + 0ed2e0d commit 76f8b02

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
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-
->onlyMethods(['setTransactionName', 'endTransaction'])
99+
->onlyMethods(['setTransactionName', 'endTransaction', 'startBackgroundTransaction'])
94100
->getMock();
95101
}
96102

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
<type name="Magento\NewRelicReporting\Plugin\CommandPlugin">
5050
<arguments>
5151
<argument name="skipCommands" xsi:type="array">
52-
<item xsi:type="boolean" name="cron:run">true</item>
5352
<item xsi:type="boolean" name="server:run">true</item>
5453
</argument>
5554
</arguments>

0 commit comments

Comments
 (0)