AddCustomParameter(string $key, string $value) AddCustomParameter(string $key, IConvertible $value)
Attaches a key/value pair of custom attributes to the current transaction.

Requirements

Compatible with all agent versions.

Must be called inside a transaction.

Description

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

These attributes are used to decorate errors and transaction traces. You can attach up to 64 of these "user" attributes per transaction (each call to this API method counts as one "user" attribute). You can also attach (or "forward") these attributes to Browser 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.AddCustomParameter("Discount Code", "Summer Super Sale");
NewRelic.Api.Agent.AddCustomParameter("Item Code", (Single)31456);