newrelic_set_appname

newrelic_set_appname(string $name) newrelic_set_appname(string $name, string $license[, bool $xmit])
Sets the New Relic app name, which controls data rollup.

Requirements

Agent version 3.1.5.111 or higher.

Description

Set the New Relic application name, which the New Relic UI uses to connect your data to the correct application. Call as early as possible. This call is useful if you can't edit your agent config file (for example, many shared hosting environments do not allow you to edit config files).

The basic version of the call simply sets the method name. Another version lets you specify a license key (if you use multiple New Relic accounts) and whether to keep or discard the existing data.

Parameters

Parameter Description
function newrelic_set_appname (string $name) : bool

$name

string

Required. Name(s) of app metrics should be reported under in New Relic user interface. Uses the same format as newrelic.appname and can set multiple application names by separating each with a semicolon ;.
function newrelic_set_appname (string $name, string $license, bool $xmit) : bool

$name

string

Required. Name(s) of app metrics should be reported under in New Relic user interface. Uses the same format as newrelic.appname and can set multiple application names by separating each with a semi-colon ;.

$license

string

Required (can be empty string). Specify a different license key to report metrics to a different New Relic account. If set to empty string, defaults to license key in the agent's newrelic.ini file.

$xmit

boolean

Optional. Defaults to false.

If false or omitted, the agent discards the current transaction and does not send any of the accumulated data to the daemon.

If true, the agent sends the data that was gathered right before executing this call. The data is associated with the new app name. This has a very slight performance impact as it takes a few milliseconds for the agent to dump its data.

Return value(s)

Returns true if the application name was successfully changed, or false otherwise.

Example(s)

Set a single app name

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_set_appname("App1");
    }
    ...
}

Set two app names

This example sets multiple app names:

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_set_appname("App1;App2");
    }
    ...
}

Set app name and license key

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_set_appname("App1", "01234567890abcde01234567890abcde01234567890");
    }
    ...
}

Set app name and keep previous data

This example sets an app name and keeps the existing data, but doesn't change the license key:

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_set_appname("App1", "", true);
    }
    ...
}

Set app name and license key, and keep previous data

This example sets the app name and license key, and keeps the existing data:

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_set_appname("App1", "01234567890abcde01234567890abcde01234567890", true);
    }
    ...
}