Azure Monitor Application InsightsのJava Agentを使ってgRPC-Javaアプリケーションを監視する

このエントリは2020/04/20現在の情報に基づいています。将来の機能追加や変更に伴い、記載内容との乖離が発生する可能性があります(2020/11/06現在、Azure Monitor Java Agent 3.0は一般提供されています)。

先日、以下のようなエントリを書いた。

Azure Monitor Application InsightsのJava Agentを使ってJavaアプリケーションを監視する
https://logico-jp.io/2020/04/16/monitor-java-applications-via-java-agent-newly-introduced-to-azure-monitor-application-insights/

前回はJava EEアプリケーションサーバーとJavaアプリケーションを監視してみたが、今回はサポート対象のgRPCのアプリケーションの通信を確認してみる。

Azure Monitor Application Insights を監視する Java のコード不要のアプリケーション – パブリックプレビュー / Java codeless application monitoring Azure Monitor Application Insights
https://docs.microsoft.com/azure/azure-monitor/app/java-in-process-agent

gRPC Basics – Java
https://grpc.io/docs/tutorials/basic/java/
https://github.com/grpc/grpc-java/tree/master/examples/src/main/java/io/grpc/examples/routeguide

今回監視対象とするgRPC-Javaのアプリケーションは、サンプルとして提供されているroute guideを使うことにした。

Agent 3.0.0 Preview 3までは、JDK 8ならびに11を使ってビルドし、実行したところ、OpenTelemetryのクラスが存在しない、という例外が出たが、これはPreview 4で修正されている。

今回の動作確認では、JDK 11 (11.0.7) とJDK 8 (1.8.252) を使用した。

動作確認

Application Insightsの構成ファイルは前回のエントリに記載した通り。今回は同じApplicationInsights.jsonファイルを使うため、クラウドロール名 (Cloud role name) を付けてクライアント、サーバーの役割を明確にしておく。JSONファイルに書き込むことでも実現できるが、サーバーとクライアントで同一ファイルを使う関係上、各Terminalにて以下のように環境変数で指定しておく。

# ServerのTerminalで
export APPLICATIONINSIGHTS_ROLE_NAME=RouteGuideServer
# ClientのTerminalで
export APPLICATIONINSIGHTS_ROLE_NAME=RouteGuideClient

指定しない場合、以下のような感じのApplication Mapが表示される(grpc-testはApplication Insightsのリソース名)。

準備が完了したので、サーバーから実行していく。

java -javaagent:applicationinsights-agent-3.0.0.jar -jar server.jar

続いて、クライアント。

java -javaagent:applicationinsights-agent-3.0.0.jar -jar client.jar

クライアント側では以下のような出力を確認できる。

2020-04-20 11:57:55.860+09 INFO  applicationinsights.diagnostics - Application Insights Codeless Agent Attach Successful
Apr 20, 2020 11:57:57 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: *** GetFeature: lat=409,146,138 lon=-746,188,906
Apr 20, 2020 11:57:59 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Found feature called "Berkshire Valley Management Area Trail, Jefferson, NJ, USA" at 40.915, -74.619
Apr 20, 2020 11:57:59 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: *** GetFeature: lat=0 lon=0
Apr 20, 2020 11:57:59 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Found no feature at 0, 0
Apr 20, 2020 11:57:59 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: *** ListFeatures: lowLat=400,000,000 lowLon=-750,000,000 hiLat=420,000,000 hiLon=-730,000,000
Apr 20, 2020 11:57:59 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Result #1: name: "Patriots Path, Mendham, NJ 07945, USA"
location {
  latitude: 407838351
  longitude: -746143763
}

...

INFO: Sending message "Third message" at 1, 0
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Sending message "Fourth message" at 1, 1
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Got message "First message" at 0, 0
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Got message "Second message" at 0, 1
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Got message "Third message" at 1, 0
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Got message "Fourth message" at 1, 1
Apr 20, 2020 11:58:07 AM io.grpc.examples.routeguide.RouteGuideClient info
INFO: Finished RouteChat

INFO: Finished RouteChat を確認して、しばし待ってからApplication InsightsのApplication Mapを確認すると、以下のような画面を確認できる。

通信部分(15呼び出し)をクリックして[パフォーマンスの調査]をクリックすると、以下のような画面が現れる。

今回も前回と同様、[(15) サンプル]をクリックして、提案されたサンプルをクリックのEnd-to-Endのトランザクションを確認すると、以下のような依存関係を含む情報を確認できる。

[すべてのテレメトリを表示します]をクリックすると、この呼び出しの中で取得したメトリックを確認できる。

User flowも同様に確認できる。

まとめ

gRPCもサポートしていることがわかったが、現時点ではOpenTelemetry関連の例外が出ている。これは今後数週間のうちに修正されるはず。何か気になったことや、機能追加して欲しい、などのフィードバックがあれば、ぜひGitHubのIssueにIssueを立てて欲しい(当然ながら英語でお願いします)。

Issue
https://github.com/microsoft/ApplicationInsights-Java/issues

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト /  変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト /  変更 )

%s と連携中