AddCustomParameter

NewRelic.Api.Agent.NewRelic.AddCustomParameter(string $key, string $value) NewRelic.Api.Agent.NewRelic.AddCustomParameter(string $key, IConvertible $value)
Attaches a custom attribute (a key/value pair) to the current transaction.

Requirements

Compatible with all agent versions.

Must be called inside a transaction.

Description

Attaches a custom attribute (a key/value pair) to the current transaction. For the attribute value, you can report either a string or an IConvertible.

Custom attributes can be used to add more detail and context to errors and transaction traces that are being reported to New Relic. For example, you might add a user name attribute to a transaction to help you filter and analyze your data. You can attach up to 64 attributes per transaction. (Each call to this API method counts as one "user" attribute.) You can also attach (or "forward") these attributes to New Relic Browser's PageView events.

For more information, see .NET agent attributes.

If you want to use your custom parameters or attributes in Insights, avoid using any of the reserved terms used by NRQL and Insights.

Parameters

Parameter Description
AddCustomParameter(string $key, string $value)

$key

string

Required. The key name to add to the transaction attributes. Only the first 255 characters are retained.

$value

string

Required. The string value to add to the current transaction. Only the first 255 characters are retained.

AddCustomParameter(string $key, IConvertible $value)

$key

string

Required. The key name to add to the transaction attributes. Only the first 255 characters are retained.

$value

IConvertible

Required. The numeric value to add to the current transaction. For Insights functions that require a numeric value (such as min(), max(), or histogram()), you must convert values to singles. Other numeric values will be converted to strings.

Example(s)

Record a numeric value

NewRelic.Api.Agent.NewRelic.AddCustomParameter("UserGuid", 1234);

Record a string value

NewRelic.Api.Agent.NewRelic.AddCustomParameter("UserName", "Data Nerd");

Record both numeric and string value

To record attributes for a coupon code (string) and an item ID code (single), you could include this code in the parent method:

NewRelic.Api.Agent.NewRelic.AddCustomParameter("Discount Code", "Summer Super Sale");
NewRelic.Api.Agent.NewRelic.AddCustomParameter("Item Code", (Single)31456);