• EnglishEspañol日本語한국어Português
  • Log inStart now

Create a custom attribute

Syntax

Java

NewRelic.setAttribute(string $name, string or float $value)

Kotlin [#kotlin]

NewRelic.setAttribute(name: String?, value: String?)
NewRelic.setAttribute(name: String?, value: Double)
NewRelic.setAttribute(name: String?, value: Boolean)

Description [#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.

You can override any of the MobileSession default attributes 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 [#parameters]

Parameter

Type

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 values [#return-values]

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

Example [#example]

Here's an example of creating an attribute with the specified text name and text value. setAttribute overwrites its previous value and type each time it is called:

Java [#java]

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

Kotlin [#kotlin]

val attributeSet = NewRelic.setAttribute("storeId", "SampleStoreId000")

Here's an example of creating an attribute with the specified text name and numeric value:

Java [#java]

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

Kotlin [#kotlin]

val attributeSet = NewRelic.setAttribute("rate", 9999.99)

Syntax

Objective-c

setAttribute:(NSString*)name value:(id) value;

Swift [#swift]

NewRelic.setAttribute(string $name, string or float $value)

Description [#description]

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

You can override any of the MobileSession default attributes 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 [#parameters]

Parameter

Type

Description

$name

string

Required. Name of the session attribute.

$value

string or float

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

Return values [#return-values]

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

Examples [#examples]

Objective-C [#obj-c]

BOOL attributeSet = [NewRelic setAttribute:@"buildConfiguration" value:@"AppStore-release"];
BOOL attributeSet = [NewRelic setAttribute:@"rate" value:@9999.99];

Swift [#swift]

var attributeSet = NewRelic.setAttribute("buildConfiguration", value: "AppStore-release")
attributeSet = NewRelic.setAttribute("rate", value: 9999.99)

Syntax

setAttribute(options: { name: string; value: string; }) => void

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string or float

Required. The value of the attribute.

Example [#example]

NewRelicCapacitorPlugin.setAttribute({ name: "CapacitorAttribute", value: "123" });

Syntax

setAttribute(attributeName: string, value: boolean | number | string): void;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

attributeName

string

Required. The name of the attribute.

value

bool

Required. The value of the attribute.

Example [#example]

NewRelic.setAttribute(Name: "CordovaAttribute", value: "123"): void;

Syntax

SetAttribute(string name, string value) : bool;
SetAttribute(string name, double value) : bool;
SetAttribute(string name, bool value) : bool;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

Example [#example]

CrossNewRelic.Current.SetAttribute("MAUIBoolAttr", false);
CrossNewRelic.Current.SetAttribute("MAUIStrAttr", "Cat");
CrossNewRelic.Current.SetAttribute("MAUINumAttr", 13.5);

Syntax

setAttribute (String name, dynamic value) : void;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

dynamic value

string

Required. The value of the attribute.

Example [#example]

NewrelicMobile.instance.setAttribute('RNCustomAttrNumber', 37);

Syntax

setAttribute(name: string, value: boolean | number | string): void;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

bool, number, or string

Required. The value of the attribute.

Example [#example]

NewRelic.setAttribute('RNCustomAttrNumber', 37);

Syntax

setAttribute(string name, string value) : bool;
setAttribute(string name, double value) : bool;
setAttribute(string name, bool value) : bool;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

Example [#example]

NewRelicAgent.SetAttribute("UnityBoolCustomAttr", false);
NewRelicAgent.SetAttribute("UnityStringCustomAttr", "Cat");
NewRelicAgent.SetAttribute('UnityCustomAttrNumber', 37);

Syntax

setStringAttribute(FString name,FString value) : void;
setDoubleAttribute(FString name,double value):void;
setBooleanAttribute(FString name ,bool value):void;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

Example [#example]

#include "NewRelicBPLibrary.h"
UNewRelicBPLibrary::setBooleanAttribute("From Unreal",true);
UNewRelicBPLibrary::setDoubleAttribute("Unreal Double", 15.0);
UNewRelicBPLibrary::setStringAttribute("Unreal String","From UnReal");

Syntax

SetAttribute(string name, string value) : bool;
SetAttribute(string name, double value) : bool;
SetAttribute(string name, bool value) : bool;

Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

Parameters [#parameters]

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

Example [#example]

CrossNewRelicClient.Current.SetAttribute("XamarinBoolAttr", false);
CrossNewRelicClient.Current.SetAttribute("XamarinStrAttr", "Cat");
CrossNewRelicClient.Current.SetAttribute("XamarinNumAttr", 13.5);
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.