Plugin Directory

Changeset 1645221


Ignore:
Timestamp:
04/25/2017 07:54:57 PM (9 years ago)
Author:
collinsinternet
Message:

Version 1.1

Location:
wp-newrelic
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • wp-newrelic/trunk/README.md

    r1570951 r1645221  
    11# WP New Relic
    22
    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.
     3WP 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).
    44
    55New Relic is a trademark of New Relic, Inc.
    66
    7 ## Admins settings
     7## Administrative settings
    88
    9 Admin 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.
     9After 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.
    1010
    1111![wp-nr-settings](https://cloud.githubusercontent.com/assets/2941333/21731687/906addd0-d47b-11e6-9f58-e71c17425906.png)
     
    1313### Capture URL Parameters
    1414
    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.
     15If 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).
    2016
    2117## Basic Config
    2218
    23 By default plugin will setup 3 configs.
    24 - newrelic.appname
    25 - newrelic.capture_params
    26 - newrelic.framework (value is wordpress)
     19By 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')
    2723
    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.
    2925
    3026## New Relic Custom Attributes
    3127
    32 Certain useful custom attrribute (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.
     28Certain 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.
    3329
    3430### User
    3531
    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 as
     32The 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`.
     33Ex: In New Relic Insights you can query Transactions for non-logged in users as
    3834```
    3935SELECT * FROM Transaction WHERE appName = '{appName}' AND user = 'not-logged-in'
     
    4137
    4238### 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 post ID 190.
     39For single posts, the post ID will be set via the `post_id` custom attribute.
     40
     41Ex: Get all Transactions for a post with ID 190.
    4642```
    4743SELECT * FROM Transaction WHERE appName = '{appName}' AND post_id = '190'
    4844```
    4945
    50 One can also query for post view count for post 190.
     46You 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.
    5147```
    5248SELECT count(*) FROM Transaction WHERE appName = '{appName}' AND post_id = '190'
     
    5551### Template
    5652
    57 For each request, template being used getting set as `template` custom parameter in transaction.
     53For each request, the Template being used is set as the `template` custom attribute.
    5854
    59 Ex: You can query all transactions for a particular template as following.
     55Ex: You can query all Transactions for a particular template.
    6056```
    6157SELECT * FROM Transaction WHERE appName = '{appName}' AND template = '{Absolute Template Path}'
     
    6460### Theme
    6561
    66 Current theme is getting set as `theme` custom parameter in transaction.
     62The current theme is set as the `theme` custom attribute.
    6763
    68 Ex: Query all transactions for "Twenty Fifteen" theme.
     64Ex: Query all Transactions running the "Twenty Fifteen" theme.
    6965```
    7066SELECT * FROM Transaction WHERE appName = '{appName}' AND theme = 'Twenty Fifteen'
     
    7369### Request type
    7470
    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_type filter.
     71There can be 3 type of requests: __web__, __ajax__ and __cli__. The current request type is set as the `request_type` custom attribute.
     72The request type can be overridden using the __wp_nr_request_type__ filter.
    7773
    78 Ex: Get all transaction for "ajax" request type
     74Ex: Get all Transactions for the "ajax" request type
    7975```
    8076SELECT * FROM Transaction WHERE appName = '{appName}' AND request_type = 'ajax'
     
    8379### Transaction Name
    8480
    85 Transaction 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).
     81The 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).
    8682Possible 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}
    8783
    8884### Custom Error Logging
    8985
    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).
     86Using the __wp_nr_log_errors__ function, any plugin/theme can log errors/notices to New Relic for the current Transaction.
     87Note: 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.
    9288
    9389```
     
    9793### Runtime of async tasks
    9894
    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 attribute in New Relic Insights.
     95This 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.
    10096
    10197## Screenshots
     
    115111## Development
    116112
     113The 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
     120The WP New Relic plugin is released under the [GNU Public License v2](http://www.gnu.org/licenses/gpl-2.0.html) or later.
     121
    117122### Issues
    118123
  • wp-newrelic/trunk/classes/class-wp-nr-apm.php

    r1570951 r1645221  
    2525        add_action( 'wp_async_task_after_job', array( $this, 'async_after_job_set_attribute' ), 9999, 1 );
    2626
    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 );
    3028    }
    3129
     
    135133                $transaction = "Single - {$post_type}";
    136134            } elseif ( is_page() ) {
    137                 $page = '';
    138135                if ( isset( $query->query['pagename'] ) ) {
    139                     $page = ' - ' . $query->query['pagename'];
     136                    $this->add_custom_parameter( 'page', $query->query['pagename'] );
    140137                }
    141                 $transaction = "Page{$page}";
     138                $transaction = "Page";
    142139            } elseif ( is_date() ) {
    143140                $transaction = 'Date Archive';
    144141            } elseif ( is_search() ) {
     142                if ( isset( $query->query['s'] ) ) {
     143                    $this->add_custom_parameter( 'search', $query->query['s'] );
     144                }
    145145                $transaction = 'Search Page';
    146146            } elseif ( is_feed() ) {
     
    150150                $transaction = "Archive - {$post_type}";
    151151            } elseif ( is_category() ) {
    152                 $cat = '';
    153152                if ( isset( $query->query['category_name'] ) ) {
    154                     $cat = ' - ' . $query->query['category_name'];
     153                    $this->add_custom_parameter( 'cat_slug', $query->query['category_name'] );
    155154                }
    156                 $transaction = "Category{$cat}";
     155                $transaction = "Category";
    157156            } elseif ( is_tag() ) {
    158                 $tag = '';
    159157                if ( isset( $query->query['tag'] ) ) {
    160                     $tag = ' - ' . $query->query['tag'];
     158                    $this->add_custom_parameter( 'tag_slug', $query->query['tag'] );
    161159                }
    162                 $transaction = "Tag{$tag}";
     160                $transaction = "Tag";
    163161            } 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}";
    167166            }
    168167
     
    183182        }
    184183    }
     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
    185205    /**
    186206     * Custom error logging
  • wp-newrelic/trunk/classes/class-wp-nr-dashboard.php

    r1570951 r1645221  
    2929        if ( wp_verify_nonce( $nonce, 'wp_nr_settings' ) ) {
    3030            $capture_url = filter_input( INPUT_POST, 'wp_nr_capture_urls' );
    31             $disable_amp = filter_input( INPUT_POST, 'wp_nr_disable_amp' );
    3231
    3332            if ( ! empty( $capture_url ) ) {
     
    3736            }
    3837
    39             if ( ! empty( $disable_amp ) ) {
    40                 $disable_amp = true;
    41             } else {
    42                 $disable_amp = false;
    43             }
    44 
    4538            if ( WP_NR_IS_NETWORK_ACTIVE ) {
    4639                update_site_option( 'wp_nr_capture_urls', $capture_url );
    47                 update_site_option( 'wp_nr_disable_amp', $disable_amp );
    4840            } else {
    4941                update_option( 'wp_nr_capture_urls', $capture_url );
    50                 update_option( 'wp_nr_disable_amp', $disable_amp );
    5142            }
    5243        }
     
    8374    public function dashboard_page() {
    8475        $is_capture = WP_NR_Helper::is_capture_url();
    85         $is_disable_amp = WP_NR_Helper::is_disable_amp();
    8676        ?>
    8777        <div class="wrap">
     
    9989                        </td>
    10090                    </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>
    10891                </table>
    10992                <?php
  • wp-newrelic/trunk/classes/class-wp-nr-helper.php

    r1570951 r1645221  
    1414     */
    1515    public static function is_capture_url() {
    16 
    1716        return self::get_setting( 'wp_nr_capture_urls' );
    18     }
    19 
    20     /**
    21      * Check if disable for AMP setting is enabled or not
    22      *
    23      * @return bool
    24      */
    25     public static function is_disable_amp() {
    26         return self::get_setting( 'wp_nr_disable_amp' );
    2717    }
    2818
  • wp-newrelic/trunk/classes/class-wp-nr.php

    r1570951 r1645221  
    1414            $this->init();
    1515        } 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
    1621            if ( WP_NR_IS_NETWORK_ACTIVE ) {
    1722                add_action( 'network_admin_notices', array( $this, 'wp_nr_not_installed_notice' ) );
  • wp-newrelic/trunk/newrelic-reporting-for-wordpress.php

    r1570951 r1645221  
    44 * Plugin Name: New Relic Reporting for WordPress
    55 * Description: New Relic APM reports for WordPress
    6  * Version:     1.0
     6 * Version:     1.1
    77 * Author:      10up
    88 * Author URI:  https://10up.com
  • wp-newrelic/trunk/readme.txt

    r1570951 r1645221  
    33Tags: New Relic, New Relic Reporting, New Relic APM Reporting, APM Reporting
    44Requires at least: 4.0
    5 Tested up to: 4.7
    6 Stable tag: 1.0
     5Tested up to: 4.7.4
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818= Admin Settings =
    1919
    20 Admin 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.
     20After 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.
    2121
    2222Capture 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.
    2523
    2624= Basic Config =
     
    108106== Changelog ==
    109107
     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
    110114= 1.0 =
    111115* First release of WP New Relic plugin.
Note: See TracChangeset for help on using the changeset viewer.