-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: instrument wordpress core callbacks on demand (#802)
Improve agent's performance by adding a new toggle around WordPress instrumentation: * `newrelic.framework.wordpress.core` - indicates if WordPress hooks callback functions, implemented in WordPress core, are to be instrumented. By default WordPress hook callbacks from WordPress core are not instrumented because it increases agent's overhead. It is however possible to enable this instrumentation with INI setting.
- Loading branch information
Showing
25 changed files
with
695 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/integration/frameworks/wordpress/mock-wordpress-app.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* A simple mock of a WordPress app */ | ||
|
||
require_once __DIR__.'/wp-config.php'; | ||
|
||
// Register core action | ||
add_action("wp_init", "wp_core_action_1"); | ||
add_action("wp_init", "wp_core_action_2"); | ||
add_action("wp_init", "wp_core_action_3"); | ||
add_action("wp_init", "wp_core_action_4"); | ||
|
||
/* Emulate loading custom plugin and theme */ | ||
require_once __DIR__.'/wp-content/plugins/mock-plugin1.php'; | ||
require_once __DIR__.'/wp-content/plugins/mock-plugin2.php'; | ||
require_once __DIR__.'/wp-content/themes/mock-theme1.php'; | ||
require_once __DIR__.'/wp-content/themes/mock-theme2.php'; | ||
|
||
// Register custom plugin action | ||
add_action("wp_loaded", "plugin1_action_1"); | ||
add_action("wp_loaded", "plugin2_action_1"); | ||
|
||
// Emulate WordPress initialization: | ||
do_action("wp_init"); | ||
do_action("wp_loaded"); | ||
|
||
// Register custom theme filter | ||
add_filter("the_content", "wp_core_filter_1"); | ||
|
||
// Register custom theme filter | ||
add_filter("template_include", "theme1_identity_filter"); | ||
add_filter("template_include", "theme2_identity_filter"); | ||
|
||
// Emulate WordPress loading a template to render a page: | ||
$template = apply_filters("template_include", "./path/to/templates/page-template.php"); | ||
|
||
// Emulate WordPress rendering the content for the page: | ||
$content = apply_filters("the_content", "Lore ipsum HTML"); |
54 changes: 54 additions & 0 deletions
54
tests/integration/frameworks/wordpress/test_wordpress_00.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Test WordPress default instrumentation. The agent should: | ||
- 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 but only when hook executes functions from custom | ||
plugin or theme; the agent must not generate hooks metrics when hook executes | ||
functions from wordpress core | ||
No errors should be generated. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
// This test checks if add_filter is instrumented and this function is only | ||
// instrumented in PHPs 7.4 because it is used to wrap hook callback functions. | ||
// Older PHPs use call_user_func_array instrumentation to wrap hook callbacks. | ||
if (version_compare(PHP_VERSION, '7.4', '<')) { | ||
die("skip: PHP >= 7.4 required\n"); | ||
} | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Supportability/framework/WordPress/detected | ||
WebTransaction/Action/page-template | ||
Supportability/InstrumentedFunction/apply_filters | ||
Supportability/InstrumentedFunction/do_action | ||
Supportability/InstrumentedFunction/add_filter | ||
Framework/WordPress/Hook/wp_loaded | ||
Framework/WordPress/Hook/template_include | ||
Framework/WordPress/Plugin/mock-plugin1 | ||
Framework/WordPress/Plugin/mock-plugin2 | ||
Framework/WordPress/Plugin/mock-theme1 | ||
Framework/WordPress/Plugin/mock-theme2 | ||
*/ | ||
|
||
/*EXPECT_METRICS_DONT_EXIST | ||
Framework/WordPress/Hook/wp_init | ||
Framework/WordPress/Hook/the_content | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
/* WordPress mock app */ | ||
require_once __DIR__.'/mock-wordpress-app.php'; |
46 changes: 46 additions & 0 deletions
46
tests/integration/frameworks/wordpress/test_wordpress_00.php7.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Test WordPress default instrumentation. The agent should: | ||
- 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 but only when hook executes functions from custom | ||
plugin or theme; the agent must not generate hooks metrics when hook executes | ||
functions from wordpress core | ||
No errors should be generated. | ||
*/ | ||
|
||
/*SKIPIF | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Supportability/framework/WordPress/detected | ||
WebTransaction/Action/page-template | ||
Supportability/InstrumentedFunction/apply_filters | ||
Supportability/InstrumentedFunction/do_action | ||
Framework/WordPress/Hook/wp_loaded | ||
Framework/WordPress/Hook/template_include | ||
Framework/WordPress/Plugin/mock-plugin1 | ||
Framework/WordPress/Plugin/mock-plugin2 | ||
Framework/WordPress/Plugin/mock-theme1 | ||
Framework/WordPress/Plugin/mock-theme2 | ||
*/ | ||
|
||
/*EXPECT_METRICS_DONT_EXIST | ||
Framework/WordPress/Hook/wp_init | ||
Framework/WordPress/Hook/the_content | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
/* WordPress mock app */ | ||
require_once __DIR__.'/mock-wordpress-app.php'; |
47 changes: 47 additions & 0 deletions
47
tests/integration/frameworks/wordpress/test_wordpress_01.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Test WordPress instrumentation when hooks are not instrumented. The agent should: | ||
- detect WordPress framework | ||
- name the web transaction as an 'Action' named after the template used to generate the page | ||
The agent should not: | ||
- detect custom plugins and themes | ||
- generate hooks metrics | ||
No errors should be generated. | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework.wordpress.hooks = false | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Supportability/framework/WordPress/detected | ||
WebTransaction/Action/page-template | ||
Supportability/InstrumentedFunction/apply_filters | ||
*/ | ||
|
||
/*EXPECT_METRICS_DONT_EXIST | ||
Supportability/InstrumentedFunction/do_action | ||
Supportability/InstrumentedFunction/add_filter | ||
Framework/WordPress/Hook/wp_loaded | ||
Framework/WordPress/Hook/template_include | ||
Framework/WordPress/Plugin/mock-plugin1 | ||
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_ERROR_EVENTS null */ | ||
|
||
/* WordPress mock app */ | ||
require_once __DIR__.'/mock-wordpress-app.php'; |
53 changes: 53 additions & 0 deletions
53
tests/integration/frameworks/wordpress/test_wordpress_02.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Test WordPress instrumentation when hooks are instrumented but custom plugins are not. | ||
This setting is not very useful unless wordpress core performance is to be observed. | ||
The agent should: | ||
- detect WordPress framework | ||
- name the web transaction as an 'Action' named after the template used to generate the page | ||
- generate hooks metrics for all callback functions executions that last longer than | ||
threshold duration; the execution time of callback functions from wordpress core, | ||
custom plugins and themes is captured. | ||
The agent should not: | ||
- detect and report custom plugins and themes | ||
No errors should be generated. | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework.wordpress.hooks = true | ||
newrelic.framework.wordpress.plugins = false | ||
newrelic.framework.wordpress.hooks_threshold = 0 | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Supportability/framework/WordPress/detected | ||
WebTransaction/Action/page-template | ||
Supportability/InstrumentedFunction/apply_filters | ||
Supportability/InstrumentedFunction/do_action | ||
Framework/WordPress/Hook/wp_loaded | ||
Framework/WordPress/Hook/template_include | ||
Framework/WordPress/Hook/wp_init | ||
Framework/WordPress/Hook/the_content | ||
*/ | ||
|
||
/*EXPECT_METRICS_DONT_EXIST | ||
Supportability/InstrumentedFunction/add_filter | ||
Framework/WordPress/Plugin/mock-plugin1 | ||
Framework/WordPress/Plugin/mock-plugin2 | ||
Framework/WordPress/Plugin/mock-theme1 | ||
Framework/WordPress/Plugin/mock-theme2 | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
/* WordPress mock app */ | ||
require_once __DIR__.'/mock-wordpress-app.php'; |
Oops, something went wrong.