Application Insights リソースの作成

注意事項

この記事は、推奨されなくなった Application Insights Classic リソースに適用されます。

この記事の情報は古く、更新されません。

ワークスペース ベースの Visual Studio Online Application Insights に移行して、新しい機能を利用します。

Application Insights では、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 リソースの作成はサポートされていません。

注意

インストルメンテーション キーのインジェストのサポートは、2025 年 3 月 31 日に終了します。 インストルメンテーション キーのインジェストは引き続き機能しますが、この機能の更新プログラムやサポートは提供されなくなります。 接続文字列に移行することで、新機能をご利用いただけます。

Azure へのサインイン

Azure サブスクリプションをお持ちでない場合は、開始する前に無料アカウントを作成してください。

Application Insights リソースの作成

Azure portal にサインインし、Application Insights リソースを作成します。

左上隅の [+] 記号、[開発者ツール]、[Application Insights] の選択を示すスクリーンショット。

設定 説明
名前 Unique value 監視しているアプリを識別する名前。
リソース グループ myResourceGroup Application Insights データをホストする新しいまたは既存のリソース グループの名前。
リージョン East US 最寄りの場所か、アプリがホストされている場所に近い場所を選択します。
リソース モード Classic または Workspace-based ワークスペースベースのリソースを使用すると、Application Insights テレメトリを共通の Log Analyticsワークスペースに送信できます。 詳細については、「ワークスペースベースの Application Insights リソース」を参照してください。

注意

異なるリソースグループ間で同じリソース名を使用できますが、グローバルに一意の名前を使用すると便利です。 リソース間クエリを実行する予定の場合は、グローバルに一意の名前を使用すると、必要な構文が簡略化されます。

必須フィールドに適切な値を入力します。 [Review + create](レビュー + 作成) を選択します。

必須フィールドでの値の入力および [確認と作成] ボタンを示すスクリーンショット。

アプリが作成された後、監視対象のアプリケーションに関するパフォーマンスと使用状況のデータが新しいウィンドウに表示されます。

インストルメンテーション キーのコピー

インストルメンテーション キーにより、テレメトリ データと関連付けるリソースが識別されます。 インストルメンテーション キーをコピーして、アプリケーションのコードに追加する必要があります。

アプリケーションでの SDK のインストール

アプリで Application Insights SDK をインストールします。 この手順は、アプリケーションの種類に大きく依存します。

インストルメンテーション キーを使用して、アプリケーションにインストールする SDK を構成します。

SDK には、テレメトリを送信する標準的なモジュールが含まれているため、それ以上コードを記述する必要はありません。 ユーザーの操作を追跡したり、問題をより詳しく診断したりするには、API を使用して、独自のテレメトリを送信します。

リソースを自動的に作成する

PowerShell または Azure CLI を使って、自動でリソースを作成します。

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 から特定のリージョンにデータを送信するには、既定のエンドポイント アドレスをオーバーライドする必要があります。 SDK ごとに必要な変更点は若干異なります。そのすべてについてこの記事で説明します。

これらの変更には、サンプル コードを調整し、QuickPulse_Endpoint_AddressTelemetryChannel_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 GovernmentAzure 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

次のステップ