針對 HTTP 500 內部服務錯誤進行疑難排解

適用于: SDK v4

針對 500 個錯誤進行疑難排解的第一個步驟是啟用 Application Insights。

如需 AppInsights 範例,請參閱 luis-with-appinsights C# 範例和 JS 範例

注意

Language Understanding (LUIS) 將于 2025 年 10 月 1 日淘汰。 從 2023 年 4 月 1 日起,您將無法建立新的 LUIS 資源。 新版的語言理解現在已提供作為 Azure AI 語言的一部分。

對話式語言理解(CLU)是 Azure AI 語言的一項功能,是 LUIS 的更新版本。 如需 Bot Framework SDK 中語言理解支援的詳細資訊,請參閱 自然語言理解

如需如何將 Application Insights 新增至現有 Bot 的相關資訊,請參閱 對話分析遙測

啟用 application Insights for ASP.NET

如需基本的 Application Insights 支援,請參閱如何 為您的 ASP.NET 網站 設定 Application Insights。 Bot Framework (從 v4.2 開始)提供額外的 Application Insights 遙測層級,但診斷 HTTP 500 錯誤並非必要。

啟用 Node.js 的 Application Insights

如需基本的 Application Insights 支援,請參閱如何使用 Application Insights 監視 Node.js 服務和應用程式。 Bot Framework (從 v4.2 開始)提供額外的 Application Insights 遙測層級,但診斷 HTTP 500 錯誤並非必要。

查詢例外狀況

分析 HTTP 狀態碼 500 錯誤最簡單的方法是從例外狀況開始。

下列查詢會告訴您最新的例外狀況:

exceptions
| order by timestamp desc
| project timestamp, operation_Id, appName

從第一個查詢中,選取一些作業識別碼,並尋找詳細資訊:

let my_operation_id = "d298f1385197fd438b520e617d58f4fb";
let union_all = () {
    union
    (traces | where operation_Id == my_operation_id),
    (customEvents | where operation_Id == my_operation_id),
    (requests | where operation_Id == my_operation_id),
    (dependencies | where operation_Id  == my_operation_id),
    (exceptions | where operation_Id == my_operation_id)
};

union_all
    | order by timestamp desc

如果您只有 exceptions ,請分析詳細資料,並查看它們是否對應至程式碼中的行。 如果您只看到來自 Channel 連線or ( Microsoft.Bot.ChannelConnector ) 的例外狀況,請參閱 [沒有 Application Insights] 事件 ,以確保 Application Insights 已正確設定,而且您的程式碼正在記錄事件。

沒有 Application Insights 事件

如果您收到 500 個錯誤,且 Bot 的 Application Insights 中沒有進一步的事件,請檢查下列各項:

確定 Bot 在本機執行

首先,使用 Bot Framework 模擬器在本機測試 Bot。

確定正在複製組態檔 (僅限.NET)

請確定部署程式期間已正確封裝您的 appsettings.json 和任何其他組態檔。

應用程式元件

確定 Application Insights 元件在部署程式期間已正確封裝。

  • Microsoft.ApplicationInsights
  • Microsoft.ApplicationInsights.TraceListener
  • Microsoft.AI.Web
  • Microsoft.AI.WebServer
  • Microsoft.AI.ServeTelemetryChannel
  • Microsoft.AI.PerfCounterCollector
  • Microsoft.AI.DependencyCollector
  • Microsoft.AI.Agent.Intercept

請確定部署程式期間已正確封裝您的 appsettings.json 和任何其他組態檔。

appsettings.json

在您的 appsettings.json 檔案中,請確定已設定檢測金鑰。

{
    "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
            "Default": "Debug",
            "System": "Information",
            "Microsoft": "Information"
        },
        "Console": {
            "IncludeScopes": "true"
        }
    }
}

驗證組態檔

請確定您的組態檔中包含 Application Insights 金鑰。

{
    "ApplicationInsights": {
        "type": "appInsights",
        "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "subscriptionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "resourceGroup": "my resource group",
        "name": "my appinsights name",
        "serviceName": "my service name",
        "instrumentationKey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "applicationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "apiKeys": {},
        "id": ""
    }
},

查看記錄

Bot ASP.NET 和 Node 會在可檢查的伺服器層級發出記錄。

設定瀏覽器以監看您的記錄

  1. 在 Azure 入口網站 開啟您的 Bot。
  2. 開啟 App Service 設定 /所有 App Service 設定 頁面,以查看所有服務設定。
  3. 開啟 App Service 的 [ 監視/ 診斷記錄 ] 頁面。
    • 確定 已啟用應用程式記錄(檔案系統)。 如果您變更此設定,請務必按一下 [ 儲存 ]。
  4. 切換至 [ 監視/ 記錄資料流程 ] 頁面。
    • 選取 [Web 服務器記錄 ],並確定您看到已連線的訊息。 您應該會看到如下的內容:

      Connecting...
      2018-11-14T17:24:51  Welcome, you are now connected to log-streaming service.
      

      讓此視窗保持開啟。

設定瀏覽器以重新開機 Bot 服務

  1. 使用個別瀏覽器,在Azure 入口網站中開啟您的 Bot。
  2. 開啟 App Service 設定 /所有 App Service 設定 頁面,以查看所有服務設定。
  3. 切換至 App Service 的 [ 概觀 ] 頁面,然後按一下 [ 重新開機 ]。
    • 如果您確定,將會提示您;選取 [ ]。
  4. 返回第一個瀏覽器視窗並監看記錄。
  5. 確認您收到新的記錄。
    • 如果沒有活動,請重新部署 Bot。
    • 然後切換至 [應用程式記錄 ] 頁面,並尋找任何錯誤。

下一步