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

Start an interaction

Syntax

Java

NewRelic.startInteraction(string $interactionName)

Kotlin [#kotlin]

NewRelic.startInteraction(actionName: String)

Description [#description]

Create an interaction to instrument a method in your Android app code.

To name an interaction that already exists and is already being tracked, see setInteractionName().

Parameters [#parameters]

Parameter

Type

Description

$interactionName

string

Required. The name you want to give to the interaction.

Return values [#return-values]

Returns an interaction ID number which can be used for ending the interaction at a certain point.

Example [#example]

Here's an example of starting to track an interaction named RefreshContacts:

Java [#java]

public class MainActivity extends Activity {
...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh:
NewRelic.startInteraction("RefreshContacts");
……
return true;
default:
return super.onOptionsItemSelected(item);
}
}
...
}

Kotlin [#kotlin]

class MainActivity : AppCompatActivity() {
.....
var client: OkHttpClient = OkHttpClient();
binding.fab.setOnClickListener { view ->
val interActionId = NewRelic.startInteraction("Getting Data From Server")
lifecycleScope.launch(Dispatchers.IO) {
val result = getRequest()
NewRelic.endInteraction(interActionId)
}
}
}
....
}

Syntax

Objective-c

+ (NSString*) startInteractionWithName:(NSString*)interactionName;

Swift [#swift]

NewRelic.startInteraction(string: "myInteractionName")

Description [#description]

This method will start an interaction trace using interactionName as the name. The interaction will record all instrumented methods until a timeout occurs or stopCurrentInteraction is called.

To name an interaction that already exists and is already being tracked, see setInteractionName().

Tip

If you use these methods, the instrumented interactions will not show up on the Interactions page, but they can be still found with a NRQL query, such as:

query SELECT name FROM Mobile SINCE 7 DAYS AGO

Parameters [#parameters]

Parameter

Type

Description

interactionName

string

Required. The name you want to give to the interaction.

Return values [#return-values]

If startInteractionWithName is called, the return value is an interactionIdentifier that must be passed to stopCurrentInteraction . But it's not required to call stopCurrentInteraction after calling start because startInteractionWithName will eventually complete intelligently.

Examples [#examples][#examples]

Objective-C [#obj-c]

NSString *identifier = [NewRelic startInteractionWithName: @"myInteractionName"];
[NewRelic stopCurrentInteraction: identifier];

Swift [#swift]

let identifier = NewRelic.startInteraction(withName: "myInteractionName")
NewRelic.stopCurrentInteraction(identifier)

Syntax

startInteraction(options: { value: string; }) => Promise<{ value: string; }>

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

options

{ value: string; }

Required. The name you want to give to the interaction.

Example [#example]

const badApiLoad = async () => {
const id = await NewRelicCapacitorPlugin.startInteraction({ value: 'StartLoadBadApiCall' });
console.log(id);
const url = 'https://fakewebsite.com/moviessssssssss.json';
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
NewRelicCapacitorPlugin.endInteraction({ interactionId: id.value });
}) .catch((error) => {
NewRelicCapacitorPlugin.endInteraction({ interactionId: id.value });
console.error(error);
});
};

Syntax

startInteraction(interactionName: string, cb?: function): Promise<InteractionId>;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

Interactioname

string

Required. The name you want to give to the interaction.

Example [#example]

const badApiLoad = async () => {
const interactionId = await NewRelic.startInteraction('StartLoadBadApiCall');
console.log(interactionId);
const url = 'https://cordova.apache.org/moviessssssssss.json';
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
NewRelic.endInteraction(interactionId);
}) .catch((error) => {
NewRelic.endInteraction(interactionId);
console.error(error);
});

Syntax

StartInteraction(string interactionName): string;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

options

{ value: string; }

Required. The name you want to give to the interaction.

Example [#example]

HttpClient myClient = new HttpClient(CrossNewRelic.Current.GetHttpMessageHandler());
string interactionId = CrossNewRelic.Current.StartInteraction("Getting data from service");
var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1"));
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
} else
{
Console.WriteLine("Unsuccessful response code");
}
CrossNewRelic.Current.EndInteraction(interactionId);

Syntax

startInteraction(String actionName);

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

string actionName

string

Required. The name you want to give to the interaction.

Example [#example]

var id = await NewrelicMobile.instance.startInteraction("Getting Data from Service");
try {
var dio = Dio();
var response = await dio.get(
'https://reqres.in/api/users?delay=15');
print(response);
NewrelicMobile.instance.endInteraction(id);
Timeline.finishSync();
} catch (e) {
print(e);
}

Syntax

startInteraction(interactionName: string): Promise<InteractionId>;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

interactionName

string

Required. The name you want to give to the interaction.

Example [#example]

const badApiLoad = async () => {
const interactionId = await NewRelic.startInteraction('StartLoadBadApiCall');
console.log(interactionId);
const url = 'https://facebook.github.io/react-native/moviessssssssss.json';
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
NewRelic.endInteraction(interactionId);
}) .catch((error) => {
NewRelic.endInteraction(interactionId);
console.error(error);
});;
};

Syntax

StartInteractionWithName((string interactionName): string;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

interactionName

string

Required. The name you want to give to the interaction.

Example [#example]

string interActionId = NewRelicAgent.StartInteractionWithName("Unity InterAction Example");
for(int i =0; i < 4;i++)
{
Thread.Sleep(1000);
}
NewRelicAgent.StopCurrentInteraction(interActionId);

Syntax

startInterAction(FString interActionName):FString;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

interActionName

FString

Required. The name you want to give to the interaction.

Example [#example]

#include "NewRelicBPLibrary.h"
FString id = UNewRelicBPLibrary::startInterAction("test Unreal InterAction");
FPlatformProcess::Sleep(6.0);
UNewRelicBPLibrary::endInterAction(id);

Syntax

StartInteraction(string interactionName): string;

Description [#description]

Track a method as an interaction.

Parameters [#parameters]

Parameter

Type

Description

interactionName

string

Required. The name you want to give to the interaction.

Example [#example]

HttpClient myClient = new HttpClient(CrossNewRelicClient.Current.GetHttpMessageHandler());
string interactionId = CrossNewRelicClient.Current.StartInteraction("Getting data from service");
var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1"));
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
} else
{
Console.WriteLine("Unsuccessful response code");
}
CrossNewRelicClient.Current.EndInteraction(interactionId);
Copyright © 2024 New Relic Inc.

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