azure-monitor-opentelemetry-ts
為 Node.js 應用程式新增 Azure Monitor 遙測
應用程式團隊需要可觀測性來進行生產環境除錯和效能監控。此技能提供完整的指導,使用 OpenTelemetry 標準為 TypeScript 和 JavaScript 應用程式進行 Azure Monitor 檢測。
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「azure-monitor-opentelemetry-ts」。 將 Azure Monitor OpenTelemetry 新增到我的 Express 應用程式
預期結果:
使用 npm install @azure/monitor-opentelemetry 安裝套件,然後在匯入 Express 之前匯入並呼叫 useAzureMonitor 並提供您的連線字串。SDK 會自動檢測 HTTP 請求、資料庫呼叫和 Azure SDK 操作。
正在使用「azure-monitor-opentelemetry-ts」。 為我的資料庫操作建立自訂 span
預期結果:
使用 trace.getTracer 取得 tracer,呼叫 startSpan 並提供操作名稱,設定屬性和資料庫類型和查詢,新增事件用於處理階段,在錯誤時記錄例外狀況,並在 finally 區塊中呼叫 end。
安全審計
安全All static analysis findings are false positives. The scanner analyzed SKILL.md documentation as executable code. The skill provides legitimate Azure Monitor OpenTelemetry instrumentation guidance with standard environment variable configuration and documented network endpoints for telemetry export.
低風險問題 (1)
風險因素
🔑 環境變數 (5)
🌐 網路存取 (1)
品質評分
你能建構什麼
生產應用程式監控
為生產環境的 Node.js API 設定全面的遙測,以追蹤請求延遲、錯誤率和相依性。
微服務分散式追蹤
使用 OpenTelemetry 標準內容傳播,啟用跨微服務的端對端追蹤可見性。
自訂商業指標
除了標準遙測外,追蹤應用程式特定的指標,如使用者操作、功能使用率和商業 KPI。
試試這些提示
協助我使用預設設定將 Azure Monitor OpenTelemetry 新增到 Express.js 應用程式。
展示如何為我的生產應用程式設定 Azure Monitor OpenTelemetry,包含自訂採樣、離線儲存和特定檢測選項。
我需要用自訂 spans、屬性和事件來追蹤特定操作。展示如何建立具有適當錯誤處理的手動追蹤。
協助我設定具有 meter provider 的自訂指標、建立過濾 span 處理器,並為我的應用程式設定記錄匯出程式。
最佳實務
- 在匯入任何其他模組之前呼叫 useAzureMonitor,以確保適當的自動檢測
- 將連線字串儲存在環境變數中,絕不要放在原始碼中
- 實作優雅關閉,使用 shutdownAzureMonitor 來清除待處理的遙測
避免
- 不要在應用程式結束時略過呼叫 shutdownAzureMonitor - 這會導致遙測資料遺失
- 避免在生產環境中將採樣比率設定為 0 - 您將遺失所有遙測資料
- 不要多次初始化 useAzureMonitor - 這會導致資源衝突