iOS アプリケーションのインストゥルメント化
EUM アプリケーションキーを取得し、iOS アプリケーションをインストゥルメント化するには、次の手順を実行します。
アプリケーションキーの取得
Getting Started Wizard を完了すると、EUM アプリケーションキーが付与されます。このキーは、ソースコードを変更するときに必要になります。場合によっては、複数のモバイルアプリケーションが同じキーを共有できます。
[Getting Started Wizard] を完了したものの、EUM アプリケーションキーを持っていない場合は、「アプリケーションキーの取得」を参照してください。
Initialize the Agent
- Objective-C
-
Edit your app's AppDelegate.m file to initialize the Mobile Agent as soon as the app launches. This registers your application and only needs to be done once in your code.
- In the AppDelegate.m file, add this import statement:
#import <ADEumInstrumentation/ADEumInstrumentation.h> - In the method
didFinishLaunchingWithOptions, create anADEumAgentConfigurationobject with the EUM App Key that you received when completing the Getting Started Wizard to initialize the iOS Agent:o initialize the iOS Agent:
Your code should look something like the following:// Example EUM App Key: "AAA-AAB-AUM" ADEumAgentConfiguration *config = [[ADEumAgentConfiguration alloc] initWithAppKey:<#EUM_APP_KEY#>];#import <ADEumInstrumentation/ADEumInstrumentation.h> #import "AppDelegate.h" // ... -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Example EUM App Key: "AAA-AAB-AUM" ADEumAgentConfiguration *config = [[ADEumAgentConfiguration alloc] initWithAppKey:<#EUM_APP_KEY#>]; // other tasks return YES; } - Configure the iOS Agent to report metrics and screenshots to the SaaS EUM Server in your region and initialize the agent by passing the
ADEumAgentConfigurationobject to the methodinitWithConfiguration. If you are using an on-premises EUM Server, see Configure the iOS Agent for On-Prem Deployments (Optional).#import <ADEumInstrumentation/ADEumInstrumentation.h> #import "AppDelegate.h" // ... -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ADEumAgentConfiguration *config = [[ADEumAgentConfiguration alloc] initWithAppKey:<#EUM_APP_KEY#>]; //The default SaaS EUM Server and Screenshot Service are in the Americas, // so you can omit the following settings if you are in the Americas. config.collectorURL = @"https://<your_region>-col.eum-appdynamics.com"; config.screenshotURL = @"https://<you_region>-image.eum-appdynamics.com/"; [ADEumInstrumentation initWithConfiguration: config]; // other tasks return YES; } - (Optional) If your application is using another tool to report crashes, the iOS Agent may warn you with the following message:
You are recommended to use only one crash reporting tool for better results. See Disable Crash Reporting for instructions on how to disable the iOS Agent's crash reporting.Agent has detected a third party crash reporting tool. You may wish to disable AppDynamics Crash Reporting by setting the crashReportingEnabled configuration flag to NO - Save the file.
- In the AppDelegate.m file, add this import statement:
- Swift
-
The iOS Agent is compatible with applications created using the Swift programming language.
- In your application's AppDelegate class, add this import statement:
import ADEumInstrumentation - In the
AppDelegateclassdidFinishLaunchingWithOptions, create anADEumAgentConfigurationobject with the EUM App Key that you received when completing the Getting Started Wizard to initialize the iOS Agent:#import <ADEumInstrumentation/ADEumInstrumentation.h> #import "AppDelegate.h" // ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = ADEumAgentConfiguration(appKey: <#EUM_APP_KEY#>) } - Configure the iOS Agent to report metrics and screenshots to the SaaS EUM Server in your region, and initialize the agent by passing the
initWith()method that takes theADEumAgentConfigurationobject as a parameter.注: If you are using an on-premises EUM Server, see Configure the iOS Agent for On-Prem Deployments (Optional).#import <ADEumInstrumentation/ADEumInstrumentation.h> #import "AppDelegate.h" // ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = ADEumAgentConfiguration(appKey: <#EUM_APP_KEY#>) config.collectorURL = "https://<your_region>.eum-appdynamics.com" config.screenshotURL = "https://<your_region>-image.eum-appdynamics.com" ADEumInstrumentation.initWith(config) // other tasks return true } // ... - (Optional) If your application is using another tool to report crashes, the iOS Agent will warn you with the following message:
We recommend you use only one crash reporting tool for better results. See Disable Crash Reporting for instructions on how to disable the iOS Agent's crash reporting.Agent has detected a third party crash reporting tool. You may wish to disable AppDynamics Crash Reporting by setting the crashReportingEnabled configuration flag to NO - Save the file.
- In your application's AppDelegate class, add this import statement:
- Apple Watch Extensions
-
Apps written for watchOS 1 contain a WatchKit extension that runs on the user's iPhone, but watchOS 2 also supports a new architecture, where the WatchKit extension runs on the Apple Watch itself. Splunk AppDynamics supports the watchOS 1 architecture, but not the new watchOS 2 architecture. Note that apps using the watchOS 1 architecture can run on both watchOS 1 and 2, so if your application is designed for watchOS 1, you can use Splunk AppDynamics on both versions of watchOS.
Because watchOS 1 apps are functionally launched in response to an interaction with the Watch UI, the SDK initialization code should be called at the point of that interaction in the iPhone app, which is usually not at the extension's
AppDelegate.mcall. The syntax remains the same.
dSYM ファイルの生成
アプリケーションがクラッシュした場合に生成されるクラッシュスナップショットに、人間が判読可能な情報をエージェントが提供できるようにするには、[ ] ファイルオプションを使用してコンパイルし、アプリケーションのデバッグシンボル(dSYM)ファイルを生成します。これを行う理由について詳しくは、「人間が判読可能なクラッシュスナップショットの取得」を参照してください。
- Xcode の Project Navigator でプロジェクトを選択します。
- ターゲットリストで、アプリケーションを構築するターゲットを選択します。
- [Build Settings] タブを選択します。
- [Build Options] セクションで、Debug Information Format が DWARF with dSYM File に設定されていることを確認します。
- Xcode プロジェクトを再構築します。
dSYM ファイルによるクラッシュのモニタ
この手順はオプションですが、クラッシュをモニターする場合は強く推奨します。Splunk AppDynamics は、アプリケーションがクラッシュスナップショット用に判読可能なスタックトレースを生成するために、dSYM ファイルを必要とします。
手順は、「dSYM ファイルのアップロード」を参照してください。
インストゥルメンテーションのカスタマイズ(オプション)
ADEumInstrumentation クラスには、Splunk AppDynamics を使用して収集および集約できるデータの種類を拡張できる追加のメソッドがあります。作成できる拡張には、次の 5 つの基本タイプがあります。
- カスタムタイマー:コード内の任意のイベントシーケンスが、複数のメソッドにまたがる場合でも、時間を計測できます
- カスタムメトリック:収集する任意の整数ベースのデータ
- ユーザデータ:任意の文字列キーと値のペアが役立つ可能性があります
- インフォメーションポイント:1 つのメソッドが呼び出される頻度と実行にかかる時間
- トピックパス(パンくずリスト):クラッシュのコンテキスト
「iOS インストゥルメンテーションのカスタマイズ」を参照してください。
Configure the iOS Agent for On-Premises Deployments (Optional)
By default, the agent is configured to send its beacons to the EUM Cloud, which is an instance of the EUM Server running on AWS. If you wish to instrument your app in an environment that is using an on-premises version of the EUM Server, you need to modify the URL to which the agent sends its beacons. You do this using the ADEumAgentConfiguration object to set the Collector URL and the Screenshot Service URL to your on-premises EUM Server URL.
https://myEUMServerURL.com:7001, the iOS Agent will know to use https://myEUMServerURL.com:7001/eumcollector to make requests to the EUM Collector. By specifying the Collector URL, you will not be able to use the SaaS deployment of the EUM Cloud for the Screenshot Service.To get the EUM Server URL:
- Open the Administration Console.
- From the left navigation bar, click Controller Settings.
- In the search field, enter eum.beacon.host or eum.beacon.https.host if you're using HTTPS.
- Copy the value for the configuration. This is your EUM Server URL.
- Objective-C
-
ADEumAgentConfiguration *adeumAgentConfig = [[ADEumAgentConfiguration alloc] initWithAppKey:<#EUM_APP_KEY#>]; // Set the Collector URL and Screenshot Service URL to the EUM Server URL. adeumAgentConfig.collectorURL = <#COLLECTOR_URL:PORT#>; adeumAgentConfig.screenshotURL = adeumAgentConfig.collectorURL; [ADEumInstrumentation initWithConfiguration:adeumAgentConfig]; - Swift
-
let configuration = ADEumAgentConfiguration(appKey: <#EUM_APP_KEY#>) // Set the Collector URL and Screenshot Service URL to the EUM Server URL. config.collectorURL = <#COLLECTOR_URL:PORT#> config.screenshotURL = config.collectorURL ADEumInstrumentation.initWith(configuration)
Enable HTTP to Send Beacons to On-Premises EUM Servers
If you use an on-premises EUM Server and you wish to use HTTP to dispatch your beacons to the EUM Server, starting with iOS 9 you need to set a flag in your app's info.plist file to allow it to use the unsecured connection. By default, HTTPS is enforced in all iOS 9 applications by App Transport Security (ATS), and the iOS Agent complies with ATS when used with the EUM Cloud.