NewRelic.recordCustomEvent(string $eventType, [string $eventName,] map<string, object> $eventAttributes)
Records a custom New Relic mobile monitoring event.
Agent version 5.12.0 or higher.
Creates and records a custom event, for use in NRQL. The event includes a list of attributes, specified as a map. Unlike using
setAttribute, adding attributes to a custom event adds them only to that event; they are not session attributes.
Important considerations and best practices include:
- You should limit the total number of event types to approximately five.
eventTypeis meant to be used for high-level categories. For example, you might create an event type
- Do not use
eventTypeto name your custom events. Create an attribute to name an event or use the optional
nameparameter. You can create many custom events; it is only event types that you should limit.
- Using the optional
nameparameter has the same effect as adding a
namekey in the
nameis a keyword used for displaying your events in the New Relic UI. To create a useful
name, you might combine several attributes (see examples).
As of New Relic Android agent version 5.12.0, the
recordEvent method is deprecated and replaced with
recordEvent method will continue to work for an unspecified period of time, but if your app contains
recordEvent methods, New Relic recommends you replace them.
Updating these methods will affect any NRQL queries and dashboards that use the deprecated event types. Be sure to adjust your NRQL queries and dashboards as needed.
For more on other Android APIs, see Send custom attributes and events.
Required. The type of event. Do not use
Optional. Use this parameter to name the event. (Using this parameter is equivalent to creating a
Optional. A map that includes a list of attributes that further designate subcategories to the
Note: Not all object types are supported. See setAttribute for details on supported types.
When setting the key for your custom attributes, be aware that there are default attributes that cannot be overridden.
true if the event is recorded successfully, or
false if not.
Basic custom event
Map attributes = new HashMap();attributes.put("attributeName1", "value1");attributes.put("attributeName1", 2);boolean eventRecorded = NewRelic.recordCustomEvent("eventType", attributes);
Custom event with several attributes
Notice how the
eventType parameter is used for a high-level category,
Map attributes = new HashMap();attributes.put("make", "Ford");attributes.put("model", "ModelT");attributes.put("color", "Black");attributes.put("VIN", "123XYZ");attributes.put("maxSpeed", 12);NewRelic.recordCustomEvent("Car", attributes);
Custom event using 'name' parameter
Map attributes = new HashMap();attributes.put("make", "Ford");attributes.put("model", "ModelT");NewRelic.recordCustomEvent("Car", "Ford Model T", attributes);