From 22ccfc5fe833c0359053cced7c19e736043515e8 Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Fri, 19 Apr 2024 09:59:23 -0400 Subject: [PATCH 1/3] feat(agent): update default for wp hooks options By default the agent will only instrument hook callbacks from plugins/themes and will not instrument hook callbacks from wordpress core. --- agent/php_nrini.c | 2 +- agent/scripts/newrelic.ini.template | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/agent/php_nrini.c b/agent/php_nrini.c index 1a5d5c831..2ed62eb10 100644 --- a/agent/php_nrini.c +++ b/agent/php_nrini.c @@ -1896,7 +1896,7 @@ static PHP_INI_MH(nr_custom_events_max_samples_stored_mh) { return SUCCESS; } -#define DEFAULT_WORDPRESS_HOOKS_OPTIONS "all_callbacks" +#define DEFAULT_WORDPRESS_HOOKS_OPTIONS "plugin_callbacks" static PHP_INI_MH(nr_wordpress_hooks_options_mh) { nrinistr_t* p; diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index eb0d24b00..094f7cc01 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1169,17 +1169,17 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; Setting: newrelic.framework.wordpress.hooks.options ; Type : string (all_callbacks, plugin_callbacks, threshold) ; Scope : per-directory -; Default: all_callbacks +; Default: plugin_callbacks ; Info : Sets the options how WordPress hooks are instrumented. ; ; New Relic agent can provide different levels of insights into WordPress hooks. -; By default, all hook callbacks functions are instrumented ("all_callbacks"). -; To reduce agent's overhead it is possible to limit the instrumentation to only -; plugin/theme callbacks ("plugin_callbacks"). Third option is to monitor hooks -; without instrumenting callbacks ("threshold"). This option does not give insights -; about plugins/themes. +; By default, only plugin/theme callbacks are instrumented ("plugin_callbacks"). +; At the cost of increased agent's overhead it is possible to extend the +; instrumentation to all hook callbacks functions ("all_callbacks")nly. Third option +; is to monitor hooks without instrumenting callbacks ("threshold"). This option +; does not give insights about plugins/themes. ; -;newrelic.framework.wordpress.hooks.options = "all_callbacks" +;newrelic.framework.wordpress.hooks.options = "plugin_callbacks" ; Setting: newrelic.framework.wordpress.hooks.threshold ; Type : time specification string ("500ms", "1s750ms" etc) From 4e99b9bd0d818612634be657ea6ccbe02643e8e8 Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Fri, 19 Apr 2024 14:20:32 -0400 Subject: [PATCH 2/3] update tests to account for new default --- .../frameworks/wordpress/test_wordpress_00.php | 8 ++++---- .../frameworks/wordpress/test_wordpress_00.php7.php | 8 ++++---- .../frameworks/wordpress/test_wordpress_00_1.php | 8 ++++---- .../frameworks/wordpress/test_wordpress_00_2.php | 8 ++++---- .../frameworks/wordpress/test_wordpress_apply_filters.php | 6 +++--- .../frameworks/wordpress/test_wordpress_do_action.php | 7 +++---- .../test_wordpress_transaction_name_hooks_on.php | 8 +++----- 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/integration/frameworks/wordpress/test_wordpress_00.php b/tests/integration/frameworks/wordpress/test_wordpress_00.php index 946e497ba..46451d5b7 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_00.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_00.php @@ -9,8 +9,8 @@ - detect WordPress framework - name the web transaction as an 'Action' named after the template used to generate the page - detect custom plugins and themes - - generate hooks metrics for all callback functions executions; the execution time of callback - functions from wordpress core, custom plugins and themes is captured. + - generate hooks metrics only for plugins and themes callback functions executions; + only the execution time of callback functions from custom plugins and themes is captured. No errors should be generated. */ @@ -40,11 +40,11 @@ functions from wordpress core, custom plugins and themes is captured. Framework/WordPress/Plugin/mock-plugin2 Framework/WordPress/Plugin/mock-theme1 Framework/WordPress/Plugin/mock-theme2 -Framework/WordPress/Hook/wp_init -Framework/WordPress/Hook/the_content */ /*EXPECT_METRICS_DONT_EXIST +Framework/WordPress/Hook/wp_init +Framework/WordPress/Hook/the_content */ /*EXPECT_ERROR_EVENTS null */ diff --git a/tests/integration/frameworks/wordpress/test_wordpress_00.php7.php b/tests/integration/frameworks/wordpress/test_wordpress_00.php7.php index fa2cfa826..adc5d1970 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_00.php7.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_00.php7.php @@ -9,8 +9,8 @@ - detect WordPress framework - name the web transaction as an 'Action' named after the template used to generate the page - detect custom plugins and themes - - generate hooks metrics for all callback functions executions; the execution time of callback - functions from wordpress core, custom plugins and themes is captured. + - generate hooks metrics only for plugins and themes callback functions executions; + only the execution time of callback functions from custom plugins and themes is captured. No errors should be generated. */ @@ -32,11 +32,11 @@ functions from wordpress core, custom plugins and themes is captured. Framework/WordPress/Plugin/mock-plugin2 Framework/WordPress/Plugin/mock-theme1 Framework/WordPress/Plugin/mock-theme2 -Framework/WordPress/Hook/wp_init -Framework/WordPress/Hook/the_content */ /*EXPECT_METRICS_DONT_EXIST +Framework/WordPress/Hook/wp_init +Framework/WordPress/Hook/the_content */ /*EXPECT_ERROR_EVENTS null */ diff --git a/tests/integration/frameworks/wordpress/test_wordpress_00_1.php b/tests/integration/frameworks/wordpress/test_wordpress_00_1.php index c12a731de..8823a86e9 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_00_1.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_00_1.php @@ -10,8 +10,8 @@ - detect WordPress framework - name the web transaction as an 'Action' named after the template used to generate the page - detect custom plugins and themes - - generate hooks metrics for all callback functions executions; the execution time of callback - functions from wordpress core, custom plugins and themes is captured. + - generate hooks metrics only for plugins and themes callback functions executions; + only the execution time of callback functions from custom plugins and themes is captured. No errors should be generated. */ @@ -34,11 +34,11 @@ functions from wordpress core, custom plugins and themes is captured. Framework/WordPress/Plugin/mock-plugin2 Framework/WordPress/Plugin/mock-theme1 Framework/WordPress/Plugin/mock-theme2 -Framework/WordPress/Hook/wp_init -Framework/WordPress/Hook/the_content */ /*EXPECT_METRICS_DONT_EXIST +Framework/WordPress/Hook/wp_init +Framework/WordPress/Hook/the_content */ /*EXPECT_ERROR_EVENTS null */ diff --git a/tests/integration/frameworks/wordpress/test_wordpress_00_2.php b/tests/integration/frameworks/wordpress/test_wordpress_00_2.php index 3dc12e750..e7ec3b8d3 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_00_2.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_00_2.php @@ -10,8 +10,8 @@ - detect WordPress framework - name the web transaction as an 'Action' named after the template used to generate the page - detect custom plugins and themes - - generate hooks metrics for all callback functions executions; the execution time of callback - functions from wordpress core, custom plugins and themes is captured. + - generate hooks metrics only for plugins and themes callback functions executions; + only the execution time of callback functions from custom plugins and themes is captured. No errors should be generated. */ @@ -34,11 +34,11 @@ functions from wordpress core, custom plugins and themes is captured. Framework/WordPress/Plugin/mock-plugin2 Framework/WordPress/Plugin/mock-theme1 Framework/WordPress/Plugin/mock-theme2 -Framework/WordPress/Hook/wp_init -Framework/WordPress/Hook/the_content */ /*EXPECT_METRICS_DONT_EXIST +Framework/WordPress/Hook/wp_init +Framework/WordPress/Hook/the_content */ /*EXPECT_ERROR_EVENTS null */ diff --git a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php index 9c2f84fa1..062f6d4e6 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php @@ -8,8 +8,8 @@ The agent should properly instrument Wordpress apply_filters hooks. Since the mocked hooks are detected by the agent as WordPress core (plugin_from_function returns NULL), and WordPress core callbacks are not instrumented by default, -therefore newrelic.framework.wordpress.core needs to be set to true for the -agent to generate the hooks metrics. +therefore newrelic.framework.wordpress.hooks.options needs to be set to +"all_callbacks" for the agent to generate the hooks metrics. */ /*SKIPIF @@ -18,7 +18,7 @@ /*INI newrelic.framework = wordpress newrelic.framework.wordpress.hooks_threshold = 0 -newrelic.framework.wordpress.core = true +newrelic.framework.wordpress.hooks.options = all_callbacks */ /*EXPECT diff --git a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php index cf3b1b50b..cad1bf607 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php @@ -8,8 +8,8 @@ The agent should properly instrument Wordpress do_action hooks. Since the mocked hooks are detected by the agent as WordPress core (plugin_from_function returns NULL), and WordPress core callbacks are not instrumented by default, -therefore newrelic.framework.wordpress.core needs to be set to true for the -agent to generate the hooks metrics. +therefore newrelic.framework.wordpress.hooks.options needs to be set to +"all_callbacks" for the agent to generate the hooks metrics. */ /*SKIPIF @@ -17,8 +17,7 @@ /*INI newrelic.framework = wordpress -newrelic.framework.wordpress.hooks_threshold = 0 -newrelic.framework.wordpress.core = true +newrelic.framework.wordpress.hooks.options = all_callbacks */ /*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 9ad96a5f7..71abe758f 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 @@ -11,17 +11,15 @@ metric should be generated and the hook function should be instrumented. However, since the mocked hooks are detected by the agent as WordPress core (plugin_from_function returns NULL), and WordPress core callbacks are not -instrumented by default, therefore newrelic.framework.wordpress.core needs -to be set to true for the agent to generate the hooks metrics. +instrumented by default, therefore therefore newrelic.framework.wordpress.hooks.options +needs to be set to "all_callbacks" for the agent to generate the hooks metrics. */ /*SKIPIF*/ /*INI newrelic.framework = wordpress -newrelic.framework.wordpress.hooks = true -newrelic.framework.wordpress.hooks_threshold = 0 -newrelic.framework.wordpress.core = true +newrelic.framework.wordpress.hooks.options = all_callbacks */ /*ENVIRONMENT From e0ff77b13d37d1efa631cb5dca02174cd1d128ca Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Mon, 22 Apr 2024 11:16:07 -0400 Subject: [PATCH 3/3] typo --- agent/scripts/newrelic.ini.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/scripts/newrelic.ini.template b/agent/scripts/newrelic.ini.template index 094f7cc01..0e5da6ab3 100644 --- a/agent/scripts/newrelic.ini.template +++ b/agent/scripts/newrelic.ini.template @@ -1175,7 +1175,7 @@ newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log" ; New Relic agent can provide different levels of insights into WordPress hooks. ; By default, only plugin/theme callbacks are instrumented ("plugin_callbacks"). ; At the cost of increased agent's overhead it is possible to extend the -; instrumentation to all hook callbacks functions ("all_callbacks")nly. Third option +; instrumentation to all hook callbacks functions ("all_callbacks"). Third option ; is to monitor hooks without instrumenting callbacks ("threshold"). This option ; does not give insights about plugins/themes. ;