HomeMagento

How To Turn Magento 2 New Relic Reporting Into Success

How To Turn Magento 2 New Relic Reporting Into Success
Like Tweet Pin it Share Share Email

New Relic reporting is one of the surpassing features with Magento 2. It is as old as Magento. The projects which are using New Relic for performance are much easier to identify the difficulties obtained on the production systems which there are fewer chances of debugging possibilities. From the feature’s viewpoint, it integrates New Relic APM (Application Performance Monitoring) and New Relic Insights with Magento 2. It is done in the same way as Blue Acorn developed new Relic Reporting extension in Magento 1. It appears to be an extension for Magento 2.

What is in the Insight?

A few times back, we were using APM functionality. It’s set up was quite simple! New Relic Agent was installed in the form of php extension to begin the things. Here you can track the code-level visibility performance. This will further allow you to analyze your code, database queries, errors, etc.

But thanks to Insight, who has brought all one level higher. This will also help the user to monitor user behavior or business transactions and analyze how the data is related to APM findings. The number of dashboards may vary with the kind of information. For example, according to user documentation, you could attach usernames to failing requests to see if particular users have any uneasy experience.

With the help of New Relic Query Language (NRQL), you can perform this tasks. It is an SQL-flavored query language which may help in making calls upon the Insights Events database.

Here s a brief discussion about it.

READ  Top 10 Safe SEO Expert Tips for Magento Stores in 2015

After installing New Relic Query Language (NRQL), find out the settings in Magento 2 administration interface.

Stores->Configuration [General]->New Relic reporting

New Relic reporting

It does not require any registration through New Relic account. One can straightaway proceed to configure it since one only requires data. Here you need to connect Magento and New Relic.

Here you will be able to monitor things like flushing your cache or deleting the product in admin to order placement on your frontend.

placement on your frontend

You will be able to monitor many things from flushing your cache or deleting the product in admin to placing the order on your frontend.

Here is how we do it?

Here is how it works for orders placed on frontend:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_place_after">
<observer name="newrelicreporting_observer_report_sales_order_place" instance="Magento\NewRelicReporting\Model\Observer\ReportOrderPlaced"/>
<observer name="newrelicreporting_newrelic_report_sales_order_place" instance="Magento\NewRelicReporting\Model\Observer\ReportOrderPlacedToNewRelic />
</event>
</config>

First it hooks up to sales_order_place_after event:

It continues by executing method ReportOrderPlaced::execute()

/**
* Reports orders placed to the database reporting_orders table
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
/** @var \Magento\Sales\Model\Order $order */
$rorder = $observer->getEvent()->getOrder();
$icount = $rorder->getTotalItemCount();
if (!is_numeric($icount) && empty($icount)) {
$ icount = $rorder->getTotalQtyOrdered();
}
$data = [
'customer_id' => $rorder->getCustomerId(),
'total' => $rorder->getGrandTotal(),
'total_base' => $rorder->getBaseGrandTotal(),
'item_count' => $icount,
'updated_at' => $this->dateTime->formatDate(true)
];
/** @var \Magento\NewRelicReporting\Model\Orders $orderModel */
$oModel = $this->ordersFactory->create();
$oModel->setData($data);
$oModel->save();
}
}

and ReportOrderPlacedToNewRelic::execute() method:

/**
* Reports orders placed to New Relic
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
/** @var \Magento\Sales\Model\Order $order */
$rorder = $observer->getEvent()->getOrder();
$icount = $rorder->getTotalItemCount();
if (!is_numeric($icount) && empty($icount)) {
$icount= $rorder->getTotalQtyOrdered();
}
$this->newRelicWrapper->addCustomParameter(Config::ORDER_PLACED, 1);
$this->newRelicWrapper->addCustomParameter(Config::ORDER_ITEMS, $itemCount);
$this->newRelicWrapper->addCustomParameter(Config::ORDER_VALUE, $order->getBaseGrandTotal());
}
}

We cannot analyze what Magento does with this report that is saved in the database. It reports to New Relic directly since add Custom Parameter only wraps agent’s function newrelic_add_custom_parameter like this:

/**
* Wrapper for 'newrelic_add_custom_parameter' function
*
* @param string $param
* @param string|int $value
* @return bool
*/
public function addCustomParameter($param, $value)
{
if (extension_loaded('newrelic')) {
newrelic_add_custom_parameter($param, $value);
return true;
}
return false;
}

Additionally, Magento will use cron to periodically report what is happening with your modules (enabling, disabling, installing, uninstalling) or general counts about your system, for example:

$this->addCustomParameters([
Config::PRODUCT_COUNT => $this->counter->getAllProductsCount(),
Config::CONFIGURABLE_COUNT => $this->counter->getConfigurableCount(),
Config::ACTIVE_COUNT => $this->counter->getActiveCatalogSize(),
Config::CATEGORY_COUNT => $this->counter->getCategoryCount(),
Config::WEBSITE_COUNT => $this->counter->getWebsiteCount(),
Config::STORE_VIEW_COUNT => $this->counter->getStoreViewsCount(),
Config::CUSTOMER_COUNT => $this->counter->getCustomerCount(),
]);

I hope this post, has helped in you understanding about New Relic Reporting in Magento.

READ  Magento 2.0 Updates, Rumors, Expectations and Needs

Author Bio:

Claudia is working as a Magento developer with Magentax and having the prestige of delivering flawless Magento services and solutions to global clientele.

Translate »