你診斷 Durable Task SDK 問題的選項,取決於你使用的 Azure 運算工具,例如 Azure 容器應用程式、Azure Kubernetes Service 叢集,或是 Azure App 服務 應用程式。 我們建議同時啟用 Application Insights與Durable Task Scheduler 監控儀表板 ,以全面掌握編排狀態與故障狀況。
Application Insights
Application Insights 是監控 Durable Task SDK 上應用程式運行的推薦方式。 你可以在Azure入口網站中使用 Application Insights Analytics 工具來查找並查詢這些追蹤事件。
每個編排實例的生命週期事件都會寫入追蹤事件至 Application Insights 的 追蹤 集合。 使用這些事件的自訂維度(例如 prop__instanceId、prop__name 和 prop__runtimeStatus)來篩選和查詢特定的編排。
| 計算服務 | 診斷日誌說明 |
|---|---|
| Azure 容器應用程式 | 使用 Log Analytics 來監控 Azure 容器應用程式中的日誌 |
| Azure App 服務 | 在 Azure App 服務 中啟用應用程式的診斷日誌 |
| Azure Kubernetes Service | 監控 Azure Kubernetes Service |
範例查詢
啟用 Application Insights 後,請在 日誌 中使用以下 KQL 查詢來調查編排行為:
尋找失敗的編排:
traces
| where customDimensions.prop__runtimeStatus == "Failed"
| project timestamp, customDimensions.prop__instanceId, customDimensions.prop__name, message
| order by timestamp desc
| take 50
依名稱顯示協調流程持續時間 (過去 24 小時):
traces
| where timestamp > ago(24h)
| where customDimensions.prop__runtimeStatus == "Completed"
| extend duration = todatetime(customDimensions.prop__completedTime) - todatetime(customDimensions.prop__createdTime)
| summarize avg(duration), max(duration), count() by tostring(customDimensions.prop__name)
使用 OpenTelemetry 進行分散式追蹤
Durable Task SDK 支援 OpenTelemetry 分散式追蹤,讓您能夠在協調流程、活動和子協調流程之間,以相互關聯的 Span 取得端對端可見度。 你可以將追蹤匯出到任何支援 OpenTelemetry 的後端,包括 Application Insights、Jaeger 或 Zipkin。
關於所有支援語言的設定說明及程式碼範例,請參見 OpenTelemetry 與 Durable Task Scheduler 的分散式追蹤。
Durable Task Scheduler 監控儀表板
Durable Task Scheduler 儀表板讓你能監控編排狀態、檢查輸入/輸出、查看執行時間軸,並管理編排(開始、暫停、繼續、終止)。 它同時可透過本地模擬器和 Azure 主機的排程器使用。
存取儀表板
-
本地模擬器:無需認證。 儀表板可於
http://localhost:8082.取得。 -
Azure 裝載的排程器:將 Durable Task Data Contributor 角色指派給您的身分,然後透過 Azure 入口網站中的工作中樞端點 URL,或在
https://dashboard.durabletask.io/存取儀表板。
完整的設定和使用指南,請參閱 使用 Durable Task Scheduler 儀表板進行協調作業的除錯和管理。
常見問題
| 癥狀 | 可能原因 | Resolution |
|---|---|---|
| 協調流程卡在「執行中」 | 活動拋出未處理的例外,且未設定重試策略 | 請查看 Application Insights 以獲取例外細節;在編排器中新增重試策略或嘗試/捕捉 |
| 活動持續無限期重試 | 重試政策沒有 maxNumberOfAttempts 限制 |
在重試政策設定中設定最大重試次數 |
| 協調流程未啟動 | 背景工作未輪詢正確的工作中樞 | 確認 連接字串 工作集線器名稱是否與排程資源相符 |
| Application Insights 中沒有痕跡 | 連線字串未設定或 SDK 未發出遙測資料 | 確認 APPLICATIONINSIGHTS_CONNECTION_STRING 是否設定;確保 OpenTelemetry Microsoft.DurableTask 來源已被註冊 |
| 儀表板未顯示協調流程 | 角色分配缺失或錯誤選擇任務中心 | 確認您具有 Durable Task Data Contributor 角色;檢查儀表板 URL 中的工作中樞名稱 |
| 編曲完成,但結果空無一物 | 活動回傳 null 或序列化失敗 |
在儀表板的歷史檢視中檢視活動輸出;檢查序列化器設定 |