Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add INI to toggle naming functionality on/off
  • Loading branch information
bduranleau-nr committed Jan 22, 2025
commit dafcd5d623fb98516c489cd12d5d9b7d75e19b87
99 changes: 53 additions & 46 deletions agent/fw_drupal8.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ NR_PHP_WRAPPER(nr_drupal8_name_the_wt_cached) {
goto end;
}

if (!NRINI(drupal_page_cache_naming)) {
name = nr_strdup("page_cache");
goto end;
}

nrfn = nr_php_find_function("newrelic_name_cached");
if (NULL == nrfn) {
nrl_warning(NRL_FRAMEWORK,
Expand Down Expand Up @@ -797,57 +802,59 @@ void nr_drupal8_enable(TSRMLS_D) {
zend_class_entry* symfony_ce = NULL;
bool inject = true;

drupal_ce = nr_php_find_class("Drupal\\Core\\Routing\\RouteMatch");
if (NRINI(drupal_page_cache_naming)) {
drupal_ce = nr_php_find_class("Drupal\\Core\\Routing\\RouteMatch");

if (NULL == drupal_ce) {
inject = false;
nrl_warning(NRL_FRAMEWORK, "Missing Drupal RouteMatch Class");
}

if (inject) {
symfony_ce
= nr_php_find_class("Symfony\\Component\\HttpFoundation\\Request");
if (NULL == symfony_ce) {
if (NULL == drupal_ce) {
inject = false;
nrl_warning(NRL_FRAMEWORK, "Missing Symfony Request Class");
nrl_warning(NRL_FRAMEWORK, "Missing Drupal RouteMatch Class");
}
}

if (inject) {
// clang-format off
retval = zend_eval_string(
"namespace newrelic\\Drupal8;"

"use Symfony\\Component\\HttpFoundation\\Request;"
"use Drupal\\Core\\Routing\\RouteMatch;"

"if (!function_exists('newrelic\\Drupal8\\newrelic_name_cached')) {"
" function newrelic_name_cached(Request $request) {"
" try {"
" $routeCollection = \\Drupal::service('router.route_provider')->getRouteCollectionForRequest($request);"
" $routeMatch = RouteMatch::createFromRequest($request);"
" $route = $routeCollection->get($routeMatch->getRouteName());"
" $defaults = $route->getDefaults();"
" if (isset($defaults['_controller'])) {"
" $controller = str_replace('::', '->', $defaults['_controller']);"
" $controller = ltrim($controller, '\\\\');"
" return $controller;"
" }"
" } catch (Throwable $e) {}"
" }"
"}",
NULL, "newrelic/Drupal8");
// clang-format on

if (SUCCESS != retval) {
nrl_warning(NRL_FRAMEWORK,
"%s: error injecting newrelic page cache naming code",
__func__);
if (inject) {
symfony_ce
= nr_php_find_class("Symfony\\Component\\HttpFoundation\\Request");
if (NULL == symfony_ce) {
inject = false;
nrl_warning(NRL_FRAMEWORK, "Missing Symfony Request Class");
}
}

if (inject) {
// clang-format off
retval = zend_eval_string(
"namespace newrelic\\Drupal8;"

"use Symfony\\Component\\HttpFoundation\\Request;"
"use Drupal\\Core\\Routing\\RouteMatch;"

"if (!function_exists('newrelic\\Drupal8\\newrelic_name_cached')) {"
" function newrelic_name_cached(Request $request) {"
" try {"
" $routeCollection = \\Drupal::service('router.route_provider')->getRouteCollectionForRequest($request);"
" $routeMatch = RouteMatch::createFromRequest($request);"
" $route = $routeCollection->get($routeMatch->getRouteName());"
" $defaults = $route->getDefaults();"
" if (isset($defaults['_controller'])) {"
" $controller = str_replace('::', '->', $defaults['_controller']);"
" $controller = ltrim($controller, '\\\\');"
" return $controller;"
" }"
" } catch (Throwable $e) {}"
" }"
"}",
NULL, "newrelic/Drupal8");
// clang-format on

if (SUCCESS != retval) {
nrl_warning(NRL_FRAMEWORK,
"%s: error injecting newrelic page cache naming code",
__func__);
}
} else {
nrl_warning(
NRL_FRAMEWORK,
"Skipped injecting page_cache naming function: Missing Classes");
}
} else {
nrl_warning(
NRL_FRAMEWORK,
"Skipped injecting page_cache naming function: Missing Classes");
}

/*
Expand Down
3 changes: 3 additions & 0 deletions agent/php_newrelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ nrinibool_t browser_monitoring_debug; /* newrelic.browser_monitoring.debug */
nrinistr_t browser_monitoring_loader; /* newrelic.browser_monitoring.loader */

nrinibool_t drupal_modules; /* newrelic.framework.drupal.modules */
nrinibool_t
drupal_page_cache_naming; /* newrelic.framework.drupal.page_cache_naming.enabled
*/
nrinibool_t wordpress_hooks; /* newrelic.framework.wordpress.hooks */
nrinistr_t
wordpress_hooks_options; /* newrelic.framework.wordpress.hooks.options */
Expand Down
8 changes: 8 additions & 0 deletions agent/php_nrini.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,14 @@ STD_PHP_INI_ENTRY_EX("newrelic.framework.drupal.modules",
zend_newrelic_globals,
newrelic_globals,
nr_on_off_dh)
STD_PHP_INI_ENTRY_EX("newrelic.framework.drupal.page_cache_naming.enabled",
"1",
NR_PHP_REQUEST,
nr_boolean_mh,
drupal_page_cache_naming,
zend_newrelic_globals,
newrelic_globals,
nr_on_off_dh)
STD_PHP_INI_ENTRY_EX("newrelic.framework.wordpress.hooks",
"1",
NR_PHP_REQUEST,
Expand Down
9 changes: 9 additions & 0 deletions agent/scripts/newrelic.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,15 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log"
;
;newrelic.framework.drupal.modules = true

; Setting: newrelic.framework.drupal.page_cache_naming.enabled
; Type : boolean
; Scope : per-directory
; Default: true
; Info : Indicates if Drupal page cache transactions should be named based
; on their _controller value or assigned a default name "page_cache".
;
;newrelic.framework.drupal.page_cache_naming.enabled = true

; Setting: newrelic.framework.wordpress.hooks
; Type : boolean
; Scope : per-directory
Expand Down
Loading