クイック スタート: アプリケーションをエンド ツー エンドで監視する

注意

Azure Spring Apps は、Azure Spring Cloud サービスの新しい名前です。 サービスの名前は新しくなりましたが、スクリーンショット、ビデオ、図などの資産の更新に取り組んでいる間、場所によってはしばらく古い名前が表示されます。

この記事の適用対象:❌ Basic または Standard ✔️ Enterprise

このクイックスタートでは、Application Insights と Log Analytics を使用して、Azure Spring Apps Enterprise プランを実行しているアプリを監視する方法について説明します。

注意

App Insights、Log Analytics、New Relic、Dynatrace、AppDynamics、Elastic、Splunk など、任意のツールとプラットフォームを使って、Spring ワークロードをエンド ツー エンドで監視できます。 詳しくは、後の「他の監視ツールを使用する」をご覧ください。

前提条件

アプリケーションを更新する

Application Insights の接続文字列を、Order Service (ASP.NET Core) アプリケーションと Cart Service (Python) アプリケーションに手動で提供する必要があります。 次の手順では、この接続文字列を提供し、Application Insights へのサンプリング レートを増やす方法について説明します。

注意

現在、Application Insights のインストルメンテーションをサポートするのは、Java と NodeJS のアプリケーションの Buildpack だけです。

  1. 次のコマンドを使用して、リソースを保持する変数を作成します。 プレースホルダーは必ず、独自の値で置き換えてください。 Azure Spring Apps サービス インスタンスの名前は、長さが 4 文字から 32 文字でなければならず、小文字、数字、およびハイフンのみを使用できます。 サービス名の最初の文字は英字でなければならず、最後の文字は英字または数字でなければなりません。

    export RESOURCE_GROUP="<resource-group-name>"
    export APP_INSIGHTS_NAME="<app-insights-name>"
    export KEY_VAULT_NAME="<key-vault-name>"
    export AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME="<Azure-Spring-Apps-service-instance-name>"
    

    Note

    既定では、APP_INSIGHTS_NAME は AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME と同じです。

  2. 次のコマンドを使って、Application Insights の接続文字列を取得し、Key Vault に設定します。

    export CONNECTION_STRING=$(az monitor app-insights component show \
        --resource-group ${RESOURCE_GROUP} \
        --app ${APP_INSIGHTS_NAME} \
        --query "connectionString" \
        --output tsv)
    
    az keyvault secret set \
        --vault-name ${KEY_VAULT_NAME} \
        --name "ApplicationInsights--ConnectionString" \
        --value ${CONNECTION_STRING}
    
  3. 次のコマンドを使って、Application Insights バインディングのサンプリング レートを更新して、使用可能なデータの量を増やします。

    az spring build-service builder buildpack-binding set \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --builder-name default \
        --name default \
        --type ApplicationInsights \
        --properties sampling-rate=100 connection_string=${CONNECTION_STRING}
    
  4. 次のコマンドを使って、アプリケーションを再起動して構成を再度読み込みます。

    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name cart-service
    
    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name order-service
    
    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name catalog-service
    
    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name frontend
    
    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name payment-service
    
  5. シングル サインオンを構成している場合は、次のコマンドを使ってアプリケーションを再起動し、ID サービス アプリの構成を再度読み込みます。

    az spring app restart \
        --resource-group ${RESOURCE_GROUP} \
        --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
        --name identity-service
    

    Java と NodeJS のアプリケーションの場合、再起動すると、新しいサンプリング レートが有効になります。 Java 以外のアプリケーションの場合、再起動すると、Key Vault の新しく追加されたインストルメンテーション キーにアクセスできるようになります。

ログを表示する

Azure Spring Apps でログを表示するには、アプリ インスタンスごとのリアルタイム ログのログ ストリーミング、または高度なクエリ機能を持つ集計されたログ用の Log Analytics の、2 つの方法があります

ログ ストリーミングを使用する

アプリケーション内を移動し、カタログを表示し、注文を行うことで、アプリケーション内のトラフィックを生成します。 キャンセルされるまで、次のコマンドを使ってトラフィックを継続的に生成します。

export GATEWAY_URL=$(az spring gateway show \
    --resource-group ${RESOURCE_GROUP} \
    --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
    --query "properties.url" \
    --output tsv)

export GATEWAY_URL=https://${GATEWAY_URL} 

cd azure-spring-apps-enterprise/load-test/traffic-generator
./gradlew gatlingRun-com.vmware.acme.simulation.GuestSimulation.java

次のコマンドを使って、Catalog Service アプリケーションから最新の 100 行のアプリケーション コンソール ログを取得します。

az spring app logs \
    --resource-group ${RESOURCE_GROUP} \
    --name catalog-service \
    --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
    --lines 100

--follow オプションを追加すると、アプリからリアルタイムのログ ストリーミングを取得できます。 次のコマンドを使って、Catalog Service アプリケーションのログ ストリーミングを試します。

az spring app logs \
    --resource-group ${RESOURCE_GROUP} \
    --name catalog-service \
    --service ${AZURE_SPRING_APPS_SERVICE_INSTANCE_NAME} \
    --follow

ヒント

さらに多くのパラメーターとログ ストリーム機能を調べるには、az spring app logs --help を使います。

Log Analytics の使用

Azure portal に移動し、作成した Log Analytics インスタンスを開きます。 Log Analytics インスタンスは、Azure Spring Apps サービス インスタンスを作成したのと同じリソース グループにあります。

Log Analytics のページで、[ログ] ペインを選んで、Azure Spring Apps に次のいずれかのサンプル クエリを実行します。

次の Kusto クエリを入力して実行して、アプリケーション ログを表示します。

AppPlatformLogsforSpring
| where TimeGenerated > ago(24h)
| limit 500
| sort by TimeGenerated
| project TimeGenerated, AppName, Log

このクエリでは、次のスクリーンショットに示すような結果が生成されます。

Screenshot of Azure portal showing example output from all application logs query.

次の Kusto クエリを入力して実行して、catalog-service アプリケーション ログを表示します。

AppPlatformLogsforSpring
| where AppName has "catalog-service"
| limit 500
| sort by TimeGenerated
| project TimeGenerated, AppName, Log

このクエリでは、次のスクリーンショットに示すような結果が生成されます。

Screenshot of Azure portal showing example output from Catalog Service application logs.

次の Kusto クエリを入力して実行し、各アプリによってスローされたエラーと例外を確認します。

AppPlatformLogsforSpring
| where Log contains "error" or Log contains "exception"
| extend FullAppName = strcat(ServiceName, "/", AppName)
| summarize count_per_app = count() by FullAppName, ServiceName, AppName, _ResourceId
| sort by count_per_app desc
| render piechart

このクエリでは、次のスクリーンショットに示すような結果が生成されます。

Screenshot of Azure portal showing example output from the Ingress Logs.

次の Kusto クエリを入力して実行し、Azure Spring Apps へのインバウンド呼び出しのすべての情報を表示します。

AppPlatformIngressLogs
| project TimeGenerated, RemoteAddr, Host, Request, Status, BodyBytesSent, RequestTime, ReqId, RequestHeaders
| sort by TimeGenerated

次の Kusto クエリを入力して実行し、Azure Spring Apps によって管理されているマネージド Spring Cloud Config Gateway のすべてのログを表示します。

AppPlatformSystemLogs
| where LogType contains "SpringCloudGateway"
| project TimeGenerated,Log

このクエリでは、次のスクリーンショットに示すような結果が生成されます。

Screenshot of Azure portal showing example output from the Spring Cloud Gateway Logs.

次の Kusto クエリを入力して実行し、Azure Spring Apps によって管理されているマネージド Spring Cloud Service Registry のすべてのログを表示します。

AppPlatformSystemLogs
| where LogType contains "ServiceRegistry"
| project TimeGenerated, Log

このクエリでは、次のスクリーンショットに示すような結果が生成されます。

Screenshot of Azure portal showing example output from service registry logs.

トレースを使用する

Azure portal で、Azure Spring Apps によって作成された Application Insights インスタンスを開き、Spring Boot アプリケーションの監視を開始します。 Application Insights インスタンスは、Azure Spring Apps サービス インスタンスを作成したのと同じリソース グループにあります。

[アプリケーション マップ] ペインに移動します。次のスクリーンショットのような表示になります。

Screenshot of Azure portal showing the Application Map of Azure Application Insights.

[パフォーマンス] ペインに移動します。次のスクリーンショットのような表示になります。

Screenshot of Azure portal showing the Performance pane of Azure Application Insights.

[パフォーマンス] > [依存関係] ペインに移動します。 ここでは、次のスクリーンショットに示すように、依存関係のパフォーマンスの値 (特に SQL 呼び出し数) を確認できます。

Screenshot of Azure portal showing the Dependencies section of the Performance pane of Azure Application Insights.

[パフォーマンス] > [ロール] ペインに移動します。 ここでは、次のスクリーンショットに示すように、個々のインスタンスまたはロールのパフォーマンス メトリックを確認できます。

Screenshot of Azure portal showing the Roles section of the Performance pane of Azure Application Insights.

次のスクリーンショットに示すように、SQL 呼び出しを選んで、コンテキスト内のエンド ツー エンドのトランザクションを表示します。

Screenshot of Azure portal showing the end-to-end transaction of an S Q L call.

[障害] > [例外] ペインに移動します。 ここでは、次のスクリーンショットに示すように、例外のコレクションを確認できます。

Screenshot of Azure portal showing application failures graphed.

メトリックを表示する

[メトリック] ペインに移動します。 ここでは、Spring Boot アプリ、Spring Cloud モジュール、および依存関係によって提供されるメトリックを確認できます。 次のスクリーンショットのグラフでは、http_server_requests[Heap Memory Used](ヒープ メモリ使用量) が示されています。

Screenshot of Azure portal showing metrics over time graph.

Spring Boot では、JVM、CPU、Tomcat、Logback などの多数のコア メトリックが登録されます。 Spring Boot の自動構成により、Spring MVC によって処理される要求のインストルメンテーションが有効になります。 REST コントローラー ProductControllerPaymentController は、@Timed マイクロメーター注釈によってクラス レベルでインストルメント化されます。

acme-catalog アプリケーションでは、次のカスタム メトリックが有効になっています: @Timed: store.products

acem-payment アプリケーションでは、次のカスタム メトリックが有効になっています: @Timed: store.payment

これらのカスタム メトリックは、次のスクリーンショットに示すように、[メトリック] ウィンドウで確認できます。

Screenshot showing custom metrics instrumented by Micrometer.

[ライブ メトリック] ペインに移動します。 ここでは、次のスクリーンショットに示すように、1 秒未満の低遅延の画面でライブ メトリックを確認できます。

Screenshot showing the live metrics of all applications.

他の監視ツールを使用する

Azure Spring Apps Enterprise プランでは、次のツールなど、他のツールへのメトリックのエクスポートもサポートされています。

  • AppDynamics
  • ApacheSkyWalking
  • Dynatrace
  • Elastic APM
  • NewRelic

次のコマンドを使って、Tanzu Build Service でビルダーにバインドを追加できます。

az spring build-service builder buildpack-binding create \
    --resource-group <resource-group-name> \
    --service <Azure-Spring-Apps-service-instance-name> \
    --builder-name <builder-name> \
    --name <binding-name> \
    --type <ApplicationInsights|AppDynamics|ApacheSkyWalking|Dynatrace|ElasticAPM|NewRelic> \
    --properties <connection-properties>
    --secrets <secret-properties>

リソースをクリーンアップする

後続のクイック スタートおよびチュートリアルを引き続き実行する場合は、これらのリソースをそのまま残しておくことができます。 不要になったら、リソース グループを削除します。これにより、リソース グループ内のリソースが削除されます。 Azure CLI を使用してリソース グループを削除するには、次のコマンドを使用します。

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

次のステップ

次のいずれかの省略可能なクイックスタートに進みます: