중요
This feature works correctly only if Default Interactions
are disabled at runtime and configured appropriately at buildtime.
Creating custom interactions
You can create custom interactions and enhance them with additional information. If custom interactions are not closed explicitly, the New Relic agent automatically closes them and sends the data to the New Relic Platform.
To create a custom interaction, use startInteraction
to begin the interaction and endInteraction
to close it. The system automatically measures the timing.
Java
// Start a custom interactionString id = NewRelic.startInteraction("Tap on Search");
// ...do some work here...
// End the custom interactionNewRelic.endInteraction(id);
Kotlin
// Start a custom interactionval id = NewRelic.startInteraction("Tap on Search")
// ...do some work here...
// End the custom interactionNewRelic.endInteraction(id)
These methods allow you to capture the duration and details of specific interactions within your application, providing deeper insights into user behavior and application performance.
Create child traces with custom interactions
Child traces are similar to custom interactions. When a parent custom interaction is closed, the New Relic agent automatically closes all child method traces associated with that parent custom interaction.
To generate child traces, use the NewRelic.startMethodTrace()
method. Here's how you can implement parent custom interactions and child traces:
Java
// Start a parent custom interactionString parentId = NewRelic.startInteraction("Main Activity");
// Start a child traceNewRelic.startMethodTrace("Load Resource From Database");
// ...do some work here...
// End the child traceNewRelic.endMethodTrace();
// Start another child traceNewRelic.startMethodTrace("Load Resource From Server");
// ...do some work here...
// End the child traceNewRelic.endMethodTrace();
// End the parent interactionNewRelic.endInteraction(parentId);
Kotlin
// Start a parent custom interactionval parentId = NewRelic.startInteraction("Main Activity")
// Start a child traceNewRelic.startMethodTrace("Loop 1 Run")
// ...do some work here...
// End the child traceNewRelic.endMethodTrace()
// Start another child traceNewRelic.startMethodTrace("Loop 2 Run")
// ...do some work here...
// End the child traceNewRelic.endMethodTrace()
// End the parent interactionNewRelic.endInteraction(parentId)
Considerations
- If you want to create custom interactions with method traces, you need to start and end the interaction without any user intervention.
- If you want to calculate the time between two interactions that involve user intervention, you should not create child traces for these interactions.
This approach enables detailed tracking and measurement of interactions within your mobile application to provide valuable insights into application performance and user behavior.