バックエンド(Spring Boot)にAzure Application Insightsを入れてリクエストを計測してみた

Spring Bootって何?

もう書かなくてもいいんじゃないかな?? (誰に言われたわけでもないけど)

https://projects.spring.io/spring-boot/projects.spring.io

導入方法

前回同様、GitHubにあったSpring Frameworkのサンプルアプリpetclinicを使い、Azure Application Insights を使用した Java Web アプリの分析 | Microsoft Docs を見ながら導入した。 最初の一歩を開発元が用意してくれてるのありがたい。

petclinicはSpring Framework定番のサンプルアプリっぽい。コミュニティで色んな派生アプリを作っている模様。

github.com

コード

GitHubに置いてみた。

https://github.com/nobiinu-and/spring-petclinic-rest/tree/monitoring-request

変更点はここで確認できる。

https://github.com/spring-petclinic/spring-petclinic-rest/compare/master...nobiinu-and:monitoring-request

試行錯誤したところ

  • Application Insightsのログを出せるようにした
  • Application InsightsのInstrumentation Keyを外出しした

Application Insightsのログを出せるようにした

Application Insightsの設定ファイルに以下を加えれば良い。

    <SDKLogger>
        <Type>CONSOLE</Type>
    </SDKLogger>

思いつきだったのに、探すの結構苦労した...orz

Application InsightsのInstrumentation Keyを外出しした

環境変数 "APPLICATION_INSIGHTS_IKEY" で指定すれば、勝手に読み込んでくれるので、修正点はなし。

Application Insights SDK は、次の順序でキーを探します。
システムのプロパティ: -DAPPLICATION_INSIGHTS_IKEY=your_ikey
環境変数: APPLICATION_INSIGHTS_IKEY
構成ファイル: ApplicationInsights.xml

見えるようになったもの

ガイドにあるようなデータが取れてる。

f:id:couger:20171126133739p:plain

f:id:couger:20171126133744p:plain

残ってる課題

SQLとかの実行時間知りたい

Azure Application Insights における依存関係の追跡 | Microsoft Docsを見ると、SQLの実行時間なども分析してるんだけども...。追加の設定が必要なのかな?

Performance monitoring for Java web apps in Azure Application Insights | Microsoft Docs この辺が参考になりそう。Agentを別立てする必要がありそうなので、今回はパス。

出力しているログも分析したい

Azure Application Insights を使用した Java トレース ログの探索 | Microsoft Docsに書いてあった。 logbackの設定を変更すればいいらしい。

参考にしたページ