Application Insights リソースの作成
Azure Application Insights には、Microsoft Azure リソースのアプリケーションに関するデータが表示されます。 したがって、新しいリソースの作成は、新しいアプリケーションを監視するための Application Insights の設定の一部です。 新しいリソースを作成した後、そのインストルメンテーション キーを取得し、それを使用し Application Insights SDK を構成できます。 インストルメンテーション キーにより、リソースとテレメトリがリンクされます。
重要
2024 年 2 月 29 日に、従来の Visual Studio Online Application Insights のサポートは終了します。 ワークスペース ベースの Visual Studio Online Application Insights に移行して、新しい機能を利用します。 2021 年 2 月以降に導入された新しいリージョンでは、クラシック Visual Studio Online Application Insights リソースの作成はサポートされていません。
Note
インストルメンテーション キーのインジェストのサポートは、2025 年 3 月 31 日に終了します。 インストルメンテーション キーのインジェストは引き続き機能しますが、この機能の更新プログラムやサポートは提供されなくなります。 接続文字列に移行することで、新機能をご利用いただけます。
Microsoft Azure にサインインする
Azure サブスクリプションをお持ちでない場合は、開始する前に無料アカウントを作成してください。
Application Insights リソースの作成
Azure portal にサインインし、Application Insights リソースを作成します。
設定 | 値 | 説明 |
---|---|---|
名前 | Unique value |
監視しているアプリを識別する名前。 |
リソース グループ | myResourceGroup |
App Insights データをホストする新しいリソース グループまたは既存のリソース グループの名前。 |
リージョン | East US |
お近くの場所か、アプリがホストされている場所の近くを選択します。 |
リソース モード | Classic または Workspace-based |
ワークスペースベースのリソースを使用すると、Application Insights テレメトリを共通の Log Analyticsワークスペースに送信できます。 詳細については、ワークスペースベースのリソースに関する記事を参照してください。 |
Note
異なるリソースグループ間で同じリソース名を使用できますが、グローバルに一意の名前を使用すると便利です。 これは、必要な構文が簡略化するため、 クロスリソース クエリを実行するする場合に便利です。
必須フィールドに適切な値を入力し、 [確認と作成] を選択します。
アプリが作成されると、新しいウィンドウが開きます。 そのウィンドウには、監視対象アプリケーションに関するパフォーマンスと使用状況データが表示されます。
インストルメンテーション キーのコピー
インストルメンテーション キーにより、利用統計情報と関連付けるリソースが識別されます。 インストルメンテーション キーをコピーして、アプリケーションのコードに追加する必要があります。
アプリケーションでの SDK のインストール
アプリで Application Insights SDK をインストールします。 この手順は、アプリケーションの種類に大きく依存します。
インストルメンテーション キーを使用して、アプリケーションにインストールする SDK を構成します。
SDK には、追加コードを記述せずにテレメトリを送信する標準的なモジュールが含まれています。 ユーザーの操作を追跡したり、問題をより詳しく診断したりするには、API を使用して、独自のテレメトリを送信します。
リソースの自動作成
PowerShell
新しい Application Insights リソースを作成します。
New-AzApplicationInsights [-ResourceGroupName] <String> [-Name] <String> [-Location] <String> [-Kind <String>]
[-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
例
New-AzApplicationInsights -Kind java -ResourceGroupName testgroup -Name test1027 -location eastus
結果
Id : /subscriptions/{subid}/resourceGroups/testgroup/providers/microsoft.insights/components/test1027
ResourceGroupName : testgroup
Name : test1027
Kind : web
Location : eastus
Type : microsoft.insights/components
AppId : 8323fb13-32aa-46af-b467-8355cf4f8f98
ApplicationType : web
Tags : {}
CreationDate : 10/27/2017 4:56:40 PM
FlowType :
HockeyAppId :
HockeyAppToken :
InstrumentationKey : 00000000-aaaa-bbbb-cccc-dddddddddddd
ProvisioningState : Succeeded
RequestSource : AzurePowerShell
SamplingPercentage :
TenantId : {subid}
このコマンドレットの詳細な PowerShell ドキュメントと、インストルメンテーション キーを取得する方法については、Azure PowerShell のドキュメントを参照してください。
Azure CLI (プレビュー)
プレビューの Application Insights Azure CLI コマンドにアクセスするには、まず次を実行する必要があります。
az extension add -n application-insights
az extension add
コマンドを実行しないと、az : ERROR: az monitor: 'app-insights' is not in the 'az monitor' command group. See 'az monitor --help'.
のようなエラー メッセージが表示されます。
これで、以下を実行して Application Insights リソースを作成できるようになりました。
az monitor app-insights component create --app
--location
--resource-group
[--application-type]
[--kind]
[--tags]
例
az monitor app-insights component create --app demoApp --location westus2 --kind web --resource-group demoRg --application-type web
結果
az monitor app-insights component create --app demoApp --location eastus --kind web --resource-group demoApp --application-type web
{
"appId": "87ba512c-e8c9-48d7-b6eb-118d4aee2697",
"applicationId": "demoApp",
"applicationType": "web",
"creationDate": "2019-08-16T18:15:59.740014+00:00",
"etag": "\"0300edb9-0000-0100-0000-5d56f2e00000\"",
"flowType": "Bluefield",
"hockeyAppId": null,
"hockeyAppToken": null,
"id": "/subscriptions/{subid}/resourceGroups/demoApp/providers/microsoft.insights/components/demoApp",
"instrumentationKey": "00000000-aaaa-bbbb-cccc-dddddddddddd",
"kind": "web",
"location": "eastus",
"name": "demoApp",
"provisioningState": "Succeeded",
"requestSource": "rest",
"resourceGroup": "demoApp",
"samplingPercentage": null,
"tags": {},
"tenantId": {tenantID},
"type": "microsoft.insights/components"
}
このコマンドの詳細な Azure CLI ドキュメントと、インストルメンテーション キーを取得する方法については、Azure CLI のドキュメントを参照してください。
既定のエンドポイントをオーバーライドする Application Insights
警告
エンドポイントの変更は推奨されません。 接続文字列に移行することで、構成を簡素化し、エンドポイントを変更しなくて済むようになります。
Application Insights から特定のリージョンにデータを送信するには、既定のエンドポイント アドレスをオーバーライドする必要があります。 SDK ごとに必要な変更点は若干異なります。そのすべてについてこの記事で説明します。 これらの変更には、サンプル コードを調整し、QuickPulse_Endpoint_Address
、TelemetryChannel_Endpoint_Address
、および Profile_Query_Endpoint_address
のプレースホルダー値をお客様の特定のリージョンに対応する実際のエンドポイント アドレスに置き換える必要があります。 この記事の末尾には、この構成が必要なリージョンのエンドポイント アドレスのリンクを記載しています。
Note
インストルメンテーション キーのインジェストのサポートは、2025 年 3 月 31 日に終了します。 インストルメンテーション キーのインジェストは引き続き機能しますが、この機能の更新プログラムやサポートは提供されなくなります。 接続文字列に移行することで、新機能をご利用いただけます。
SDK コードの変更
Note
applicationinsights.config ファイルは、SDK のアップグレードが実行されるたびに自動的に上書きされます。 SDK のアップグレードを実行した後は、リージョン固有のエンドポイント値を必ず再入力します。
<ApplicationInsights>
...
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector">
<QuickPulseServiceEndpoint>Custom_QuickPulse_Endpoint_Address</QuickPulseServiceEndpoint>
</Add>
</TelemetryModules>
...
<TelemetrySinks>
<Add Name = "default">
<TelemetryChannel>
<EndpointAddress>TelemetryChannel_Endpoint_Address</EndpointAddress>
</TelemetryChannel>
</Add>
</TelemetrySinks>
...
<ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights">
<ProfileQueryEndpoint>Profile_Query_Endpoint_address</ProfileQueryEndpoint>
</ApplicationIdProvider>
...
</ApplicationInsights>
エンドポイントの変更が必要なリージョン
現在、エンドポイントの変更が必要なリージョンは Azure Government と Azure China のみです。
リージョン | エンドポイント名 | 値 |
---|---|---|
Azure 中国 | テレメトリ チャネル | https://dc.applicationinsights.azure.cn/v2/track |
Azure 中国 | QuickPulse (Live Metrics) | https://live.applicationinsights.azure.cn/QuickPulseService.svc |
Azure 中国 | Profile Query | https://dc.applicationinsights.azure.cn/api/profiles/{0}/appId |
Azure Government | テレメトリ チャネル | https://dc.applicationinsights.us/v2/track |
Azure Government | QuickPulse (Live Metrics) | https://quickpulse.applicationinsights.us/QuickPulseService.svc |
Azure Government | Profile Query | https://dc.applicationinsights.us/api/profiles/{0}/appId |
現在、一般的に `api.applicationinsights.io' によってアクセスされる Application Insights REST API をお使いの場合、お客様のリージョンのローカルのエンドポイントを使用する必要があります。
リージョン | エンドポイント名 | 値 |
---|---|---|
Azure 中国 | REST API | api.applicationinsights.azure.cn |
Azure Government | REST API | api.applicationinsights.us |
次のステップ
- 診断検索
- メトリックを探索する
- Analytics クエリを作成する
- Azure Government のカスタム変更の詳細については、Azure の監視と管理の詳細なガイダンスを参照してください。
- Azure China の詳細については、Azure China プレイブックのページを参照してください。