💬
【Azure Functions】 - Application Insightsのログが表示されない問題を解決する方法
執筆日
2025/1/20
発生事象
以下の記事のようにHTTPトリガーのFunctionsを構築し、テストを実行しました。
その際に、Application Insightsでログを確認したのですが何も表示されませんでした。トランザクション検索で検索しても0件でした。
対処方法
以下のDocsのようにAzure Monitor OpenTelemetryを有効にする。
手順
-
requirements.txt
に以下を追加するazure-monitor-opentelemetry
-
local.setting.json
に以下を追加する"APPLICATIONINSIGHTS_CONNECTION_STRING":<Application insightsの接続文字列>
-
function_app.py
に以下を組み込むimport os from azure.monitor.opentelemetry import configure_azure_monitor # Retrieve the connection string from environment variables connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") # Configure OpenTelemetry to use Azure Monitor with the connection string configure_azure_monitor(connection_string=connection_string)
-
環境をセットアップし、Azure Functionsを開始する
python -m venv .venv .venv\scripts\activate pip install -r .\requirements.txt func start
-
テストを実施
-
Application Insightsのログを確認し、ログが出ていることを確認する
Discussion