Changeset 1645221
- Timestamp:
- 04/25/2017 07:54:57 PM (9 years ago)
- Location:
- wp-newrelic
- Files:
-
- 9 added
- 7 edited
-
tags/1.1 (added)
-
tags/1.1/README.md (added)
-
tags/1.1/classes (added)
-
tags/1.1/classes/class-wp-nr-apm.php (added)
-
tags/1.1/classes/class-wp-nr-dashboard.php (added)
-
tags/1.1/classes/class-wp-nr-helper.php (added)
-
tags/1.1/classes/class-wp-nr.php (added)
-
tags/1.1/newrelic-reporting-for-wordpress.php (added)
-
tags/1.1/readme.txt (added)
-
trunk/README.md (modified) (9 diffs)
-
trunk/classes/class-wp-nr-apm.php (modified) (4 diffs)
-
trunk/classes/class-wp-nr-dashboard.php (modified) (4 diffs)
-
trunk/classes/class-wp-nr-helper.php (modified) (1 diff)
-
trunk/classes/class-wp-nr.php (modified) (1 diff)
-
trunk/newrelic-reporting-for-wordpress.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-newrelic/trunk/README.md
r1570951 r1645221 1 1 # WP New Relic 2 2 3 WP New Relic (WPNR) is designed to use with [New Relic APM](https://newrelic.com/application-monitoring) which uses [New Relic PHP Agent API](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api) to properly augment existing metrics with valuable WordPress details such as templates, users, request type, transaction names etc. This plugin is tested with PHP Agent 6.7.0.174.3 WP New Relic (WPNR) is designed to be used with the [New Relic APM](https://newrelic.com/application-monitoring), and uses the [New Relic PHP Agent API](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api) to augment existing metrics with valuable WordPress details such as templates, users, request type, and [Transaction](https://docs.newrelic.com/docs/apm/transactions) names. This plugin is tested with New Relic's PHP Agent version 6.7.0.174. Data collected by this plugin can be queried in [New Relic's Insights](https://newrelic.com/insights/) product, using [New Relic Query Language (NRQL)](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference). 4 4 5 5 New Relic is a trademark of New Relic, Inc. 6 6 7 ## Admin ssettings7 ## Administrative settings 8 8 9 A dmin settings can be browse after activating plugin. You should see a new option named __New Relic__ under Tools menu. In case of WPMU, it could be found in network dashboard.9 After activating the plugin, You will see a new option named __New Relic__ under the Tools menu in your WordPress Dashboard. If you are running WordPress in Network Mode, the settings page will be found in your Network Dashboard. 10 10 11 11  … … 13 13 ### Capture URL Parameters 14 14 15 If Capture URLs setting is enabled, it will capture URL parameters for displaying in transaction traces. 16 17 ### Disable for AMP 18 19 If Disable for AMP setting is enabled, it will disable New Relic for AMP endpoints. 15 If the __Capture URLs__ setting is enabled, the plugin will capture URL parameters for displaying in Transaction traces. As an example, turning on this feature will store a URL like http://example.com/?p=1234, while leaving it off will result in the URL being stored as http://example.com/. This feature can be useful for debugging or providing granular data if required. In certain cases, however, it can cause confusion by creating a "false positive" appearance of multiple URLs (e.g. UTM codes or tracking info from social media). 20 16 21 17 ## Basic Config 22 18 23 By default plugin will setup 3 configs.24 - newrelic.appname25 - newrelic.capture_params26 - newrelic.framework (value is wordpress)19 By default the plugin will setup 3 New Relic configuration parameters: 20 - [newrelic.appname](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration#inivar-appname) 21 - [newrelic.capture_params](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration#inivar-capture_params) 22 - [newrelic.framework](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration#inivar-framework) (default value is 'wordpress') 27 23 28 appname and capture_params config can be override using __wp_nr_config filter__. __wp_nr_setup_config__action hook can also be used to setup any extra config.24 __appname__ and __capture_params__ config can be overridden using the [__wp_nr_config__](https://github.com/10up/wp-newrelic/blob/9ec2b8d5c9e72504052a98cbb76d2e4b2e1b2b29/classes/class-wp-nr-apm.php#L36) filter. The [__wp_nr_setup_config__](https://github.com/10up/wp-newrelic/blob/9ec2b8d5c9e72504052a98cbb76d2e4b2e1b2b29/classes/class-wp-nr-apm.php#L51) action hook can also be used to setup any extra config. 29 25 30 26 ## New Relic Custom Attributes 31 27 32 Certain useful custom attr ribute (just like WordPress post meta) will be set for each event which can provide additional information using key-value pair. You can query events and filter them using these attributes in New Relic Insights. See [NRQL reference](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference) for more details on how to query events.28 Certain useful custom attributes (you can think of these as 'post meta for New Relic') will be set for each event and can provide additional information related to your WordPress installation. You can query events and filter them using these attributes in New Relic Insights. See the [NRQL reference](https://docs.newrelic.com/docs/insights/new-relic-insights/using-new-relic-query-language/nrql-reference) for more details on how to query events. 33 29 34 30 ### User 35 31 36 User attribute is getting set using [newrelic_set_user_attributes](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-set-user-attributes). If user is logged in, user ID will be set to user attribute and if not it will be set to`not-logged-in`. 37 Ex: In New Relic Insights you can query transactions for non-logged in users as32 The user attribute is set using [newrelic_set_user_attributes](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-set-user-attributes). If the user is logged in, the user ID will be set as the user attribute and if not the user attribute will be set to `not-logged-in`. 33 Ex: In New Relic Insights you can query Transactions for non-logged in users as 38 34 ``` 39 35 SELECT * FROM Transaction WHERE appName = '{appName}' AND user = 'not-logged-in' … … 41 37 42 38 ### Post ID 43 For single post , post ID will be set via `post_id` custom parameter in transaction.44 45 Ex: Get all transactions for a postID 190.39 For single posts, the post ID will be set via the `post_id` custom attribute. 40 41 Ex: Get all Transactions for a post with ID 190. 46 42 ``` 47 43 SELECT * FROM Transaction WHERE appName = '{appName}' AND post_id = '190' 48 44 ``` 49 45 50 One can also query for post view count for post 190.46 You can also perform more complex queries, such as counting the number of views for a post. This can be helpful for determining top content on your site. 51 47 ``` 52 48 SELECT count(*) FROM Transaction WHERE appName = '{appName}' AND post_id = '190' … … 55 51 ### Template 56 52 57 For each request, t emplate being used getting set as `template` custom parameter in transaction.53 For each request, the Template being used is set as the `template` custom attribute. 58 54 59 Ex: You can query all transactions for a particular template as following.55 Ex: You can query all Transactions for a particular template. 60 56 ``` 61 57 SELECT * FROM Transaction WHERE appName = '{appName}' AND template = '{Absolute Template Path}' … … 64 60 ### Theme 65 61 66 Current theme is getting set as `theme` custom parameter in transaction.62 The current theme is set as the `theme` custom attribute. 67 63 68 Ex: Query all transactions for"Twenty Fifteen" theme.64 Ex: Query all Transactions running the "Twenty Fifteen" theme. 69 65 ``` 70 66 SELECT * FROM Transaction WHERE appName = '{appName}' AND theme = 'Twenty Fifteen' … … 73 69 ### Request type 74 70 75 There can be 3 type of requests namely web, ajax and cli. Current request type getting set as `request_type` custom parameter in transaction.76 Request type can be override using wp_nr_request_typefilter.71 There can be 3 type of requests: __web__, __ajax__ and __cli__. The current request type is set as the `request_type` custom attribute. 72 The request type can be overridden using the __wp_nr_request_type__ filter. 77 73 78 Ex: Get all transaction for"ajax" request type74 Ex: Get all Transactions for the "ajax" request type 79 75 ``` 80 76 SELECT * FROM Transaction WHERE appName = '{appName}' AND request_type = 'ajax' … … 83 79 ### Transaction Name 84 80 85 T ransaction name is getting set as per the main WP_Query parameters using [newrelic_name_transaction](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-name-wt).81 The Transaction name is set based on the main WP_Query parameters using [newrelic_name_transaction](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-name-wt). 86 82 Possible values are Default Home Page, Front Page, Blog Page, Network Dashboard, Dashboard, Single - {post_type}, Page - {pagename}, Date Archive, Search Page, Feed, Archive - {post_type}, Category - {cat_name}, Tag - {tag_name}, Tax - {taxonomy} - {term} 87 83 88 84 ### Custom Error Logging 89 85 90 Using __wp_nr_log_errors__ function, any plugin/theme can log errors/notices to New Relic for current transaction.91 Note: This function can be used more than once but only last use will be considered to log the error to New Relic. It’s limitation of [PHP Agent API](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-notice-error).86 Using the __wp_nr_log_errors__ function, any plugin/theme can log errors/notices to New Relic for the current Transaction. 87 Note: This function can be called more than once, but only the last call will log the error to New Relic. This is a known limitation of the [PHP Agent API](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-notice-error). As a reminder, since the PHP Agent runs only when PHP does, any cached requests will not appear in your error logs. 92 88 93 89 ``` … … 97 93 ### Runtime of async tasks 98 94 99 This plugin also tracks runtime of [gearman](https://github.com/10up/WP-Gears) async tasks. Gearman async task run for a particular hook and it’s runtime can be track using “wp_async_task-{hook}” custom attributein New Relic Insights.95 This plugin also tracks the runtime of [gearman](https://github.com/10up/WP-Gears) async tasks. A Gearman async task run for a particular hook and its runtime can be tracked using the “wp_async_task-{hook}” custom attribute and queried in New Relic Insights. 100 96 101 97 ## Screenshots … … 115 111 ## Development 116 112 113 The WP New Relic plugin is developed and maintained by 10up, Inc. 114 <p align="center"> 115 <a href="http://10up.com/contact/"><img src="https://10updotcom-wpengine.s3.amazonaws.com/uploads/2016/10/10up-Github-Banner.png" width="850"></a> 116 </p> 117 118 ### License 119 120 The WP New Relic plugin is released under the [GNU Public License v2](http://www.gnu.org/licenses/gpl-2.0.html) or later. 121 117 122 ### Issues 118 123 -
wp-newrelic/trunk/classes/class-wp-nr-apm.php
r1570951 r1645221 25 25 add_action( 'wp_async_task_after_job', array( $this, 'async_after_job_set_attribute' ), 9999, 1 ); 26 26 27 if ( WP_NR_Helper::is_disable_amp() ) { 28 add_action( 'pre_amp_render_post', array( $this, 'disable_nr_autorum' ), 9999, 1 ); 29 } 27 add_action( 'pre_amp_render_post', array( $this, 'disable_nr_autorum' ), 9999, 1 ); 30 28 } 31 29 … … 135 133 $transaction = "Single - {$post_type}"; 136 134 } elseif ( is_page() ) { 137 $page = '';138 135 if ( isset( $query->query['pagename'] ) ) { 139 $ page = ' - ' . $query->query['pagename'];136 $this->add_custom_parameter( 'page', $query->query['pagename'] ); 140 137 } 141 $transaction = "Page {$page}";138 $transaction = "Page"; 142 139 } elseif ( is_date() ) { 143 140 $transaction = 'Date Archive'; 144 141 } elseif ( is_search() ) { 142 if ( isset( $query->query['s'] ) ) { 143 $this->add_custom_parameter( 'search', $query->query['s'] ); 144 } 145 145 $transaction = 'Search Page'; 146 146 } elseif ( is_feed() ) { … … 150 150 $transaction = "Archive - {$post_type}"; 151 151 } elseif ( is_category() ) { 152 $cat = '';153 152 if ( isset( $query->query['category_name'] ) ) { 154 $ cat = ' - ' . $query->query['category_name'];153 $this->add_custom_parameter( 'cat_slug', $query->query['category_name'] ); 155 154 } 156 $transaction = "Category {$cat}";155 $transaction = "Category"; 157 156 } elseif ( is_tag() ) { 158 $tag = '';159 157 if ( isset( $query->query['tag'] ) ) { 160 $t ag = ' - ' . $query->query['tag'];158 $this->add_custom_parameter( 'tag_slug', $query->query['tag'] ); 161 159 } 162 $transaction = "Tag {$tag}";160 $transaction = "Tag"; 163 161 } elseif ( is_tax() ) { 164 $tax = key( $query->tax_query->queried_terms ); 165 $term = implode( ' | ', $query->tax_query->queried_terms[ $tax ]['terms'] ); 166 $transaction = "Tax - {$tax} - {$term}"; 162 $tax = key( $query->tax_query->queried_terms ); 163 $term = implode( ' | ', $query->tax_query->queried_terms[ $tax ]['terms'] ); 164 $this->add_custom_parameter( 'term_slug', $term ); 165 $transaction = "Tax - {$tax}"; 167 166 } 168 167 … … 183 182 } 184 183 } 184 185 /** 186 * Adds a custom parameter through `newrelic_add_custom_parameter` 187 * Prefixes the $key with 'wpnr_' to avoid collisions with NRQL reserved words 188 * 189 * @see https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-custom-param 190 * 191 * @param $key string Custom parameter key 192 * @param $value string Custom parameter value 193 * @return bool 194 */ 195 public function add_custom_parameter( $key, $value ) { 196 if ( function_exists( 'newrelic_add_custom_parameter' ) ) { 197 //prefixing with wpnr_ to avoid collisions with reserved works in NRQL 198 $key = 'wpnr_' . $key; 199 return newrelic_add_custom_parameter( $key, apply_filters( 'wp_nr_add_custom_parameter', $value, $key ) ); 200 } 201 202 return false; 203 } 204 185 205 /** 186 206 * Custom error logging -
wp-newrelic/trunk/classes/class-wp-nr-dashboard.php
r1570951 r1645221 29 29 if ( wp_verify_nonce( $nonce, 'wp_nr_settings' ) ) { 30 30 $capture_url = filter_input( INPUT_POST, 'wp_nr_capture_urls' ); 31 $disable_amp = filter_input( INPUT_POST, 'wp_nr_disable_amp' );32 31 33 32 if ( ! empty( $capture_url ) ) { … … 37 36 } 38 37 39 if ( ! empty( $disable_amp ) ) {40 $disable_amp = true;41 } else {42 $disable_amp = false;43 }44 45 38 if ( WP_NR_IS_NETWORK_ACTIVE ) { 46 39 update_site_option( 'wp_nr_capture_urls', $capture_url ); 47 update_site_option( 'wp_nr_disable_amp', $disable_amp );48 40 } else { 49 41 update_option( 'wp_nr_capture_urls', $capture_url ); 50 update_option( 'wp_nr_disable_amp', $disable_amp );51 42 } 52 43 } … … 83 74 public function dashboard_page() { 84 75 $is_capture = WP_NR_Helper::is_capture_url(); 85 $is_disable_amp = WP_NR_Helper::is_disable_amp();86 76 ?> 87 77 <div class="wrap"> … … 99 89 </td> 100 90 </tr> 101 <tr>102 <th scope="row"><label for="wp_nr_disable_amp"><?php esc_html_e( 'Disable for AMP', 'wp-newrelic' ); ?></label></th>103 <td>104 <input type="checkbox" name="wp_nr_disable_amp" <?php checked( true, $is_disable_amp ) ?>>105 <p class="description"><?php esc_html_e( 'Enable this to disable New Relic for AMP.', 'wp-newrelic' ) ?></p>106 </td>107 </tr>108 91 </table> 109 92 <?php -
wp-newrelic/trunk/classes/class-wp-nr-helper.php
r1570951 r1645221 14 14 */ 15 15 public static function is_capture_url() { 16 17 16 return self::get_setting( 'wp_nr_capture_urls' ); 18 }19 20 /**21 * Check if disable for AMP setting is enabled or not22 *23 * @return bool24 */25 public static function is_disable_amp() {26 return self::get_setting( 'wp_nr_disable_amp' );27 17 } 28 18 -
wp-newrelic/trunk/classes/class-wp-nr.php
r1570951 r1645221 14 14 $this->init(); 15 15 } else { 16 // enable a bypass for installations where you might want to install the plugin only on a specified set of servers 17 if ( defined( 'WP_NR_DISABLE_INSTALL_NOTICE' ) && true === WP_NR_DISABLE_INSTALL_NOTICE ) { 18 return; 19 } 20 16 21 if ( WP_NR_IS_NETWORK_ACTIVE ) { 17 22 add_action( 'network_admin_notices', array( $this, 'wp_nr_not_installed_notice' ) ); -
wp-newrelic/trunk/newrelic-reporting-for-wordpress.php
r1570951 r1645221 4 4 * Plugin Name: New Relic Reporting for WordPress 5 5 * Description: New Relic APM reports for WordPress 6 * Version: 1. 06 * Version: 1.1 7 7 * Author: 10up 8 8 * Author URI: https://10up.com -
wp-newrelic/trunk/readme.txt
r1570951 r1645221 3 3 Tags: New Relic, New Relic Reporting, New Relic APM Reporting, APM Reporting 4 4 Requires at least: 4.0 5 Tested up to: 4.7 6 Stable tag: 1. 05 Tested up to: 4.7.4 6 Stable tag: 1.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 18 18 = Admin Settings = 19 19 20 A dmin settings can be browse after activating plugin. You should see a new option named __New Relic__ under Tools menu. In case of WPMU, it could be found in network dashboard.20 After activating the plugin, You will see a new option named __New Relic__ under the Tools menu in your WordPress Dashboard. If you are running WordPress in Network Mode, the settings page will be found in your Network Dashboard. 21 21 22 22 Capture URL Parameters: If Capture URLs setting is enabled, it will capture URL parameters for displaying in transaction traces. 23 24 Disable for AMP: If Disable for AMP setting is enabled, it will disable New Relic for AMP endpoints.25 23 26 24 = Basic Config = … … 108 106 == Changelog == 109 107 108 = 1.1 = 109 * Transaction grouping. (Props nicholasio) 110 * Disabling NREUM on AMP pages. (Props goldenapples) 111 * PHP warning fix. 112 * Constant to allow disabling of installation notice. (Props tott) 113 110 114 = 1.0 = 111 115 * First release of WP New Relic plugin.
Note: See TracChangeset
for help on using the changeset viewer.