• /
  • EnglishEspañol日本語한국어Português
  • Inicia sesiónComenzar ahora

Create a custom attribute

Syntax

Java

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

Kotlin

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

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

    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

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

    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

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

Kotlin

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

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

Java

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

Kotlin

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

Syntax

Objective-c

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

Swift

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

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

    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

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

    Examples

    Objective-C

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

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

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string or float

Required. The value of the attribute.

Example

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

Syntax

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

Description

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

Parameters

Parameter

Type

Description

attributeName

string

Required. The name of the attribute.

value

bool

Required. The value of the attribute.

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

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

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

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

dynamic value

string

Required. The value of the attribute.

Example

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

Syntax

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

Description

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

bool, number, or string

Required. The value of the attribute.

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

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

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

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

Example

#include "NewRelicBPLibrary.h"
UNewRelicBPLibrary::setBooleanAttribute("From Unreal",true);
UNewRelicBPLibrary::setDoubleAttribute("Unreal Double", 15.0);
UNewRelicBPLibrary::setStringAttribute("Unreal String","From UnReal");
Screenshot of the Unreal Engine Plugin Create Attribute

Syntax

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

Description

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

Parameters

Parameter

Type

Description

name

string

Required. The name of the attribute.

value

string, double, or bool

Required. The value of the attribute.

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.