We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

New Relic Support

Hello,

Has anyone ever tried to install New Relic to monitor a website or system ?

We are building a massive ERP for advertising agencies, in this case is a rewrite of the software, but now using a framework and best practices. I picked Phalcon from other frameworks for my team to develop, but now that we are putting an alpha test online I discovered that Phalcon and New Relic don't mix.

New Relic has became one of the most important tools for monitoring our systems.

Is it that difficult to put that support ? If someone point me the stepping stones I would try it.



6.9k
Accepted
answer

We use it with several apps. Theres no real difference in how new relic operates with other apps. Inside of your index.php toss in your app_name code

if (extension_loaded ('newrelic')) {
    newrelic_set_appname ("AppNameGoesHere");
}

You of course need your extension loaded and configured with your license key, but phalcon has nothing to do with that.

edited Jun '15

Reading New Relic's docs induces you to think the framework has to implement those functions. I already tested and it worked great, I've put this in my Base Controller:

<?php
$moduleName = $this->dispatcher->getModuleName();
$controllerName = $this->dispatcher->getControllerName();
$actionName = $this->dispatcher->getActionName();
if (extension_loaded ('newrelic')) {
    newrelic_name_transaction ($moduleName. '/'. $controllerName . '/' . $actionName);
}

And the Javascript includes in my main template (header and footer), it's already gathering info.

Another approach is to not put it in a base controller and attach it to the dispatcher. For example, this works for me:

$app->before(function () use ($app) {
    if (extension_loaded('newrelic')) {
        newrelic_name_transaction($app->router->getMatchedRoute()->getPattern());
    }
});

Notice also that I'm recommending sending the route pattern to New Relic, not just the module/controller/action. I find this better to visualize in NewRelic.