重要
この機能は、 Default Interactions
が実行時に無効にされ、 ビルド時に適切に構成されている場合にのみ正しく動作します。
カスタムインタラクションの作成
カスタムインタラクションを作成し、追加情報で強化することができます。カスタムインタラクションが明示的に閉じられていない場合、New Relic エージェントはそれを自動的に閉じ、データを New Relic プラットフォームに送信します。
カスタム インタラクションを作成するには、 startInteraction
を使用してインタラクションを開始し、 endInteraction
を使用して終了します。システムは自動的にタイミングを測定します。
Java
// Start a custom interactionString id = NewRelic.startInteraction("Tap on Search");
// ...do some work here...
// End the custom interactionNewRelic.endInteraction(id);
コトリン
// Start a custom interactionval id = NewRelic.startInteraction("Tap on Search")
// ...do some work here...
// End the custom interactionNewRelic.endInteraction(id)
これらのメソッドを使用すると、アプリケーション内の特定のインタラクションの継続時間と詳細をキャプチャでき、インサイトでユーザーの動作とアプリケーションのパフォーマンスをより深く知ることができます。
カスタムインタラクションで子トレースを作成する
子トレースはカスタムインタラクションに似ています。親カスタムインタラクションが閉じられると、New Relic エージェントはその親カスタムインタラクションに関連付けられているすべての子メソッド トレースを自動的に閉じます。
子トレースを生成するには、 NewRelic.startMethodTrace()
メソッドを使用します。親カスタムインタラクションと子トレースを実装する方法は次のとおりです。
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);
コトリン
// 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)
考察
- トレースメソッドを使用してカスタムインタラクションを作成する場合は、ユーザーの介入なしでインタラクションを開始および終了する必要があります。
- ユーザーの介入を伴う 2 つのインタラクション間の時間を計算する場合は、これらのインタラクションの子トレースを作成しないでください。
このアプローチにより、モバイル アプリケーション内のインタラクションの詳細な追跡と測定が可能になり、アプリケーションのパフォーマンスとユーザーの行動に貴重なインサイトを提供できます。