diff --git a/agent/fw_wordpress.c b/agent/fw_wordpress.c index b47384dbd..5299d1a48 100644 --- a/agent/fw_wordpress.c +++ b/agent/fw_wordpress.c @@ -215,6 +215,21 @@ static void free_wordpress_metadata(void* metadata) { nr_free(metadata); } +static inline void nr_wordpress_hooks_create_metric(nr_segment_t* segment, + const char* hook_name) { + if (NULL == segment) { + return; + } + // need to capture 'now' because segment has not finished yet and therefore + // can't use segment->stop_time + nrtime_t now = nr_txn_now_rel(segment->txn); + nrtime_t duration = nr_time_duration(segment->start_time, now); + if (duration >= NRINI(wordpress_hooks_threshold)) { + // only create metrics for hooks above threshold + nr_wordpress_create_metric(segment, NR_WORDPRESS_HOOK_PREFIX, hook_name); + } +} + static char* nr_wordpress_plugin_from_function(zend_function* func TSRMLS_DC) { const char* filename = NULL; size_t filename_len; @@ -452,6 +467,9 @@ NR_PHP_WRAPPER(nr_wordpress_exec_handle_tag) { NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag); NR_PHP_WRAPPER_CALL; + if (0 == NRINI(wordpress_plugins)) { + nr_wordpress_hooks_create_metric(auto_segment, NRPRG(wordpress_tag)); + } NRPRG(wordpress_tag) = old_tag; if (NULL == NRPRG(wordpress_tag)) { NRPRG(check_cufa) = false; @@ -541,6 +559,9 @@ NR_PHP_WRAPPER(nr_wordpress_apply_filters) { NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag); NR_PHP_WRAPPER_CALL; + if (0 == NRINI(wordpress_plugins)) { + nr_wordpress_hooks_create_metric(auto_segment, NRPRG(wordpress_tag)); + } NRPRG(wordpress_tag) = old_tag; if (NULL == NRPRG(wordpress_tag)) { NRPRG(check_cufa) = false; @@ -644,14 +665,15 @@ void nr_wordpress_enable(TSRMLS_D) { nr_php_wrap_user_function(NR_PSTR("do_action_ref_array"), nr_wordpress_exec_handle_tag TSRMLS_CC); - + if (0 != NRINI(wordpress_plugins)) { #if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO - nr_php_add_call_user_func_array_pre_callback( - nr_wordpress_call_user_func_array TSRMLS_CC); + nr_php_add_call_user_func_array_pre_callback( + nr_wordpress_call_user_func_array TSRMLS_CC); #else - nr_php_wrap_user_function(NR_PSTR("add_filter"), - nr_wordpress_add_filter); + nr_php_wrap_user_function(NR_PSTR("add_filter"), + nr_wordpress_add_filter); #endif + } } } diff --git a/agent/php_newrelic.h b/agent/php_newrelic.h index 82d746b78..f869351c0 100644 --- a/agent/php_newrelic.h +++ b/agent/php_newrelic.h @@ -268,6 +268,8 @@ nrinistr_t browser_monitoring_loader; /* newrelic.browser_monitoring.loader */ nrinibool_t drupal_modules; /* newrelic.framework.drupal.modules */ nrinibool_t wordpress_hooks; /* newrelic.framework.wordpress.hooks */ +nrinitime_t wordpress_hooks_threshold; /* newrelic.framework.wordpress.hooks_threshold */ +nrinibool_t wordpress_plugins; /* newrelic.framework.wordpress.plugins */ nrinistr_t wordpress_hooks_skip_filename; /* newrelic.framework.wordpress.hooks_skip_filename */ diff --git a/agent/php_nrini.c b/agent/php_nrini.c index cea0f216f..13471ba60 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -2206,6 +2206,22 @@ STD_PHP_INI_ENTRY_EX("newrelic.framework.wordpress.hooks", zend_newrelic_globals, newrelic_globals, nr_on_off_dh) +STD_PHP_INI_ENTRY_EX("newrelic.framework.wordpress.hooks_threshold", + "1ms", + NR_PHP_REQUEST, + nr_time_mh, + wordpress_hooks_threshold, + zend_newrelic_globals, + newrelic_globals, + 0) +STD_PHP_INI_ENTRY_EX("newrelic.framework.wordpress.plugins", + "0", + NR_PHP_REQUEST, + nr_boolean_mh, + wordpress_plugins, + zend_newrelic_globals, + newrelic_globals, + nr_on_off_dh) STD_PHP_INI_ENTRY_EX("newrelic.framework.wordpress.hooks_skip_filename", "", NR_PHP_REQUEST, diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index e55296cd4..7e7e6ce6b 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1166,6 +1166,23 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; ;newrelic.framework.wordpress.hooks = true +; Setting: newrelic.framework.wordpress.hooks_threshold +; Type : time specification string ("500ms", "1s750ms" etc) +; Scope : per-directory +; Default: 1ms +; Info : Sets the threshold above which the New Relic agent will record a +; wordpress hooks. +; +;newrelic.framework.wordpress.hooks_threshold = 1ms + +; Setting: newrelic.framework.wordpress.plugins +; Type : boolean +; Scope : per-directory +; Default: false +; Info : Indicates if WordPress plugins are to be instrumented. +; +;newrelic.framework.wordpress.plugins = false + ; Setting: newrelic.application_logging.enabled ; Type : boolean ; Scope : per-directory diff --git a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php index e0f072592..223127ef8 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php @@ -13,6 +13,7 @@ /*INI newrelic.framework = wordpress +newrelic.framework.wordpress.hooks_threshold = 0 */ /*EXPECT diff --git a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php index ab70d7d53..901cdbdfc 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php @@ -13,6 +13,7 @@ /*INI newrelic.framework = wordpress +newrelic.framework.wordpress.hooks_threshold = 0 */ /*EXPECT diff --git a/tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_on.php b/tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_on.php index 2b77a7487..66488513f 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_on.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_on.php @@ -16,6 +16,7 @@ /*INI newrelic.framework = wordpress newrelic.framework.wordpress.hooks = true +newrelic.framework.wordpress.hooks_threshold = 0 */ /*ENVIRONMENT