RecordCustomEvent

RecordCustomEvent(string $event_name, IEnumerable $attributes)
Records a custom event with the given name and attributes.

Requirements

Agent version 4.6.29.0 or higher.

Compatible with all app types.

Description

Records a custom event with the given name and attributes. Creating a custom event allows you to query that data in New Relic Insights.

For Insights functions that require a numeric value (such as min(), max(), or histogram()), you must convert values to singles before recording, as shown in the example.

Sending a lot of events can increase the memory overhead of the agent. Additionally, posts greater than 1MB in size will not be recorded regardless of the maximum number of events.

Parameters

Parameter Description

$event_name

string

Required. The name of the event type to record. Only the first 255 characters are retained. The name can only contain alphanumeric characters, underscores _, and colons :. For additional restrictions on event type names, see Reserved words.

$attributes

IEnumerable

Required. Specify key/value pairs of attributes to annotate the event.

Example(s)

Record only string values

var eventAttributes = new Dictionary<string, object>() {{"foo", "bar"},{"alice", "bob"}};
NewRelic.Api.Agent.NewRelic.RecordCustomEvent("MyCustomEvent", eventAttributes);

Convert values to singles before recording

If you're reporting numeric values, convert them to singles so you can use them with Insights numeric functions:

var eventAttributes = new Dictionary<string, object>() {{"foo", "bar"},{"baz", (Single)1}};
NewRelic.Api.Agent.NewRelic.RecordCustomEvent("MyCustomEvent", eventAttributes);