newrelic/newrelic-php-agent

Support for PHP Framework Yii2

razvanphp opened this issue · 4 comments

Hello,

I see that in the documentation of the agent it's stated that Yii 1.x support is built-in for automatic framework detection, but we've noticed that for Yii 2 this is not the case.

To give you some context about this, Yii 2.0 was released in Oct 2014 and it's been well maintained since then to be a reputable PHP framework used in (many) production deployments.

Yii 1.1 end of life was declared since 2023, but it still receives security updates from the community till 2026.

Since the integration extensions are not so great and have low quality of code, was wondering if it would be possible to develop the framework detection in the Newrelic Agent for everybody, I'm sure the community would love that.

Can we support somehow with the testing and implementation? Are contributions welcome for this? I could probably do it myself with some guidance and testing support.

PS: we also sent this internally through support, Feature Request ID: NR-158719

Thank you in advance!
R

For reference, here is the current detection trigger code:

void nr_yii_enable(TSRMLS_D) {
nr_php_wrap_user_function(NR_PSTR("CAction::runWithParams"),
nr_yii_runWithParams_wrapper TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("CInlineAction::runWithParams"),
nr_yii_runWithParams_wrapper TSRMLS_CC);
}

This is the referenced source code from Yii1:

In Yii2, the Action class is renamed to:

Yii2 has automatic route naming function getUniqueId() that we should use, it prepends the module name too, when present.

Please let me know if I can provide more information for fixing this.

Discovered also the path here:

{"Yii", "yii", NR_PSTR("framework/yii.php"), 0, nr_yii_enable, NR_FW_YII},
{"Yii", "yii", NR_PSTR("framework/yiilite.php"), 0, nr_yii_enable, NR_FW_YII},

This file is now named Yii.php, so correct path for v2 would be yiisoft/yii2/Yii.php or just yii2/Yii.php

The biggest problem is that currently the ErrorHandler is not wrapped at all, so no errors are displayed in NewRelic...
I can see for other frameworks that this is implemented:

NR_PHP_WRAPPER(nr_laravel5_exception_report) {

@razvanphp Thank you for providing the details of changes in Yii2 and your contribution. Our team is actively looking into incorporating these updates in one of the upcoming agent release.

I can confirm that this works with the official version of PHP agent now.