1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

App Service + Java + Application Insightsでのログ欠損

Posted at

発生した事象

  • App Serviceに対して負荷試験を実施
  • テストリクエストを発行する端末側のリクエストログとApplication Insights側のリクエストログを突合すると件数が一致しない(=Application Insights側でログが欠損している)
  • Application Insightsで以下クエリを実行するとRetainedPercentageが100%になっていない(=ログが欠けている)ことも確認
    union requests
    | summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType 
    

環境

  • App Service (Windows)
  • App Service上ではJavaアプリケーションを実行
  • Application Insightsは自動インストルメンテーション(App Service管理画面でApplication Insightsとの関連付けを設定するのみ)
  • Application Insightsで「データのサンプリング」設定はおこなっていない。(既定値の「すべてのデータ(100%)を受信する」になっている)

原因

レート制限付きサンプリングによりログが欠損していることが判明。
SDK バージョンが 3.4.0 以降の場合、デフォルトでレート制限付きサンプリングが有効になっている。デフォルト設定のままだと、1秒あたり最大約5リクエストのログしか取得されない。

Rate-limited sampling
Starting from 3.4.0, rate-limited sampling is available and is now the default.

If no sampling is configured, the default is now rate-limited sampling configured to capture at most (approximately) five requests per second, along with all the dependencies and logs on those requests.

引用元:https://learn.microsoft.com/ja-jp/azure/azure-monitor/app/java-standalone-config#rate-limited-sampling

ログを漏れなく取得する設定

固定率のサンプリングでサンプリング率を 100 に設定する。
設定はApp Serviceの環境変数からおこなえる。

App Serviceの管理画面を開き、[設定]→[環境変数]を選択。アプリ設定の[追加]ボタンをクリックし、以下のアプリケーション設定を追加する。
 
名前:APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE
値 :100

APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE.png

env_setting.png

その他の参考情報

Application Insights にテレメトリが保存されなかった場合のトラブルシューティングについて

Japan Azure Monitoring Support Blogの記事。よくまとまっているので、初めにこちらに目を通すとよい。

Sampling in Application Insights

言語によってサンプリング動作が異なることが書かれている。Java以外の言語でのサンプリングはまずこのページを確認するとよいと思われる。

このページでJavaのことも触れられているのだが、サンプリングの既定動作が変わったことが反映されておらず、内容が古いかもしれない。(2024/9/21時点)

By default no sampling is enabled in the Java autoinstrumentation and SDK.

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?