3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Application Insights のクエリーを試してみた

Posted at

先日 Durable Functions のハックフェストで、プロダクトチームのChris を観察していると、彼はデバッグの時にApplication Insightsを使いまくっていた。あー、プロダクトチームの人もわしらと同じツール使うんだと思ったのと同時に、Application Insights のクエリーは相当デバッグに役立ちそう。そこでちょっと試してみた。

ApplicationInsights.png

クエリーの構文

クエリーの構文は、SQL と似た構文になっていて、本当にいろいろなことができる。

このページのクエリを一個一個試していたのだけど、数時間経っても半分も終わらないぐらい沢山あった。検索、ソート、サマリ、平均、join、グラフの出力、PowerBIやExcel へのエクスポートなどガチでなんでもできる感じ。出来過ぎて1日で終わらなかった。
シンプルにデバッグに役立つような自作クエリーを試してみる。

検索できるデータの種類

これは下記の通り。各項目ごとに属性を持っている。これらについて検索をしたり、サマリをしたりできる。これは相当便利。

apinsighttype.png

最近のExceptionの検出

このレベルだと、デフォルトのグラフからたどれるのだが、自分の練習でやってみる。エラー種別ごとのカウントをとってみよう。先のページのサンプルは、requests ばかりだったので、exceptions で調べてみる。

exceptions 
| where timestamp > ago(1d)
| summarize count=sum(itemCount) by type

exceptions のうち、1日内のものに関して、type 毎にカウントのサマリを表示する。こうすれば、どんな Exception が何個出ているかわかる。ここでは、SqlExceptionが気になるのでそれの詳細を見てみたい。

exception01.png

グラフもボタン一つ。

exception03.png

じゃあ具体的な Exception の内容の詳細を取得してみよう。

exceptions 
| where timestamp > ago(1d)
| where type == "System.Data.SqlClient.SqlException"

こんな感じで詳細が見れる。

exception02.png

結論

この他にも沢山の紹介しきれないぐらいのクエリーが出来た。requests だと、国ごとの数値とかもサマリできた。Exception でも、client_CountryOrRegion があるので、国ごとの Exception とかも出力できる。上記のリファレンスページを見ながらになるけど、今後はガンガンに使ってみよう。便利そう!

Resource

これに尽きる。ちなみに、LogAnalytics も同じ構文(たぶん同じ基盤使ってる)らしいので、これを覚えたらどっちも使えそうでいい感じ。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?