setAttribute

NewRelic.setAttribute(string $name, string or float $value)
Creates a session-level attribute shared by multiple Mobile event types. Overwrites its previous value and type each time it is called.

Requirements

Agent version 5.0.0 or higher.

Description

This static method creates a session-level custom attribute with a specified name and value. This method overwrites its previous value and type each time it is called. The created attribute is shared by multiple Mobile event types.

For more context on how to use this API, see the Android API guide.

You can override any of the MobileSession default attributes for New Relic Insights except:

  • appId
  • appName
  • accountId
  • carrier
  • category
  • deviceManufacturer
  • deviceModel
  • eventType
  • install
  • lastInteraction
  • memUsageMb
  • newRelicVersion
  • osMajorVersion
  • osName
  • osVersion
  • platform
  • platformVersion
  • sessionDuration
  • sessionId
  • timestamp
  • type
  • upgradeFrom
  • uuid
  • Anything prefixed with NewRelic

Parameters

Parameter Description

$name

string

Required. Name of the attribute.

$value

string or float

Required. The second parameter passed can be either a string value or a float value.

Return value(s)

Returns true if recorded successfully, and false if it doesn't.

Example(s)

Set attribute with string value

The following creates an attribute with the specified text name and text value. setAttribute overwrites its previous value and type each time it is called.

boolean attributeSet = NewRelic.setAttribute("storeId", "SampleStoreId000");

Set attribute with numeric value

Creates an attribute with the specified text name and numeric value:

boolean attributeSet = NewRelic.setAttribute("rate", 9999.99);

For more help

Recommendations for learning more: