New Relic for WordPress
After New Relic is enabled on a WordPress environment:
- It is enabled on 10% of total requests per WordPress environment. If needed, New Relic can be enabled on up to 50% of requests for an environment.
- The New Relic agent is activated on both batch and web containers for WordPress environments; batch containers run WP-CLI commands and also run WordPress Cron events.
- The New Relic agent is not installed on any other parts of VIP’s infrastructure (i.e., the VIP CDN or database containers). Only requests that hit the origin can be traced. Requests served from the edge cache cannot be traced by New Relic.
New Relic’s documentation provides additional instructions for controlling which WordPress-specific metrics are sent to New Relic.
New Relic PHP API and SDK
New Relic maintains a suite of PHP functions that can be used to add data to transactions, name transactions, etc. Their documentation provides a Guide to using the PHP agent API. VIP uses this API to enhance the data provided by all VIP WordPress applications.
Custom PHP INI configuration is not offered for individual WordPress applications (sites) on VIP, but some of the configurations can be set in PHP at runtime using ini_set()
.
Separate apps out on a per-site basis for multisite
By default, New Relic monitoring data for all network sites on a WordPress multisite environment will be displayed together. To view New Relic monitoring data on a site-per-app basis, the newrelic_set_appname()
function can be added to vip-config.php
or to a file in client-mu-plugins
.
For example:
if ( extension_loaded( 'newrelic' ) && defined( 'VIP_GO_APP_ENVIRONMENT' ) && 'production' === VIP_GO_APP_ENVIRONMENT ) {
newrelic_set_appname( $_SERVER['HTTP_HOST'] );
}
Network sites that share the same root domain will require additional logic for newrelic_set_appname()
to distinguish between them (e.g., if site ID 2 is https://example.com/foo and site ID 3 is https://example.com/bar).
To do this, a version of the following code example should be added to a file in client-mu-plugins
(not vip-config.php
):
add_action( 'init', 'my_new_relic_appname', -1 );
/**
* Set application name for New Relic.
*
* This is because we want to keep the main site appname the same as before so all data/reports are in the same place.
*
* Ensure PHP agent is available and only when not the main site.
*/
function my_new_relic_appname() {
if ( extension_loaded( 'newrelic' ) &&
defined( 'VIP_GO_APP_ENVIRONMENT' ) &&
'production' === VIP_GO_APP_ENVIRONMENT &&
! is_main_site()
) {
$parsed_site_url = wp_parse_url( site_url() );
$path = $parsed_site_url['path'] ?? '';
newrelic_set_appname( $_SERVER['HTTP_HOST'] . $path );
}
}
New Relic browser monitoring
New Relic browser monitoring measures the speed and performance of end users as they navigate to a site from different web browsers, devices, operating systems, and networks.
By default, New Relic browser monitoring is disabled on new VIP Platform environments.
Prerequisites
- Only customers with an Enhanced, Signature, or Premier package, and some customers on legacy contracts can enable Browser Monitoring Lite.
- New Relic must already be enabled on the environment before Browser Monitoring Lite can be enabled.
To enable Browser Monitoring Lite for an environment, either remove or comment out the newrelic_disable_autorum()
function found in vip-config.php
:
if ( function_exists( 'newrelic_disable_autorum' ) ) {
newrelic_disable_autorum();
}
Temporarily disable New Relic browser monitoring
After enabling, New Relic browser monitoring is loaded on each page via JavaScript. To modify this behavior and only load the JavaScript conditionally—or to prevent it from loading entirely—it is recommended to hook onto template_redirect
with the wpcom_vip_disable_new_relic_js()
helper function.
The following code snippet disables the New Relic browser monitoring JavaScript from loading. This code should be added to theme or plugin code, or within a file added to client-mu-plugins
(not in vip-config.php
).
/**
* Disable New Relic's browser metrics
*
* Removes New Relic's JavaScript for tracking browser metrics, including page load times, Apdex score, and more.
*/
add_action( 'template_redirect', 'wpcom_vip_disable_new_relic_js' );
Last updated: May 16, 2024