技能 Azure Monitor OpenTelemetry Exporter for Java
📦

Azure Monitor OpenTelemetry Exporter for Java

安全

將 OpenTelemetry 資料匯出至 Azure Monitor

此技能協助 Java 開發人員將 OpenTelemetry 追蹤、指標和日誌匯出至 Azure Monitor 和 Application Insights。它提供已棄用匯出器套件的程式碼範例,以及遷移至建議的 autoconfigure 解決方案的指引。

支援: Claude Codex Code(CC)
🥉 72 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「Azure Monitor OpenTelemetry Exporter for Java」。 展示如何在我的 Java 應用程式中設定 Azure Monitor OpenTelemetry 匯出器

預期結果:

若要在 Java 中設定 Azure Monitor OpenTelemetry 匯出器,請將 autoconfigure 相依性新增至您的 pom.xml 並設定連接字串。建議的方法是使用 azure-monitor-opentelemetry-autoconfigure 而非已棄用的匯出器。設定 APPLICATIONINSIGHTS_CONNECTION_STRING 環境變數,並使用 AutoConfiguredOpenTelemetrySdk.builder() 初始化 SDK。

正在使用「Azure Monitor OpenTelemetry Exporter for Java」。 如何建立具有 Azure Monitor 自訂屬性的 span?

預期結果:

從 OpenTelemetry 取得 Tracer,使用 tracer.spanBuilder() 建立 Span,使用 setAttribute() 設定屬性,並確保在 finally 區塊中呼叫 span.end()。使用搭配 makeCurrent() 的 try-with-resources 以進行正確的內容傳播。使用 span.recordException() 記錄例外��以便在 Application Insights 中進行錯誤追蹤。

安全審計

安全
v1 • 2/25/2026

This is a prompt-only documentation skill containing code examples for using the Azure Monitor OpenTelemetry Exporter library. Static analysis scanned 0 files and detected 0 security issues. The skill provides informational content about a deprecated Microsoft library with migration guidance. No executable code, network calls, or file system access is present in the skill itself.

0
已掃描檔案
0
分析行數
0
發現項
1
審計總數
未發現安全問題
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
50
社群
100
安全
74
規範符合性

你能建構什麼

為 Java 應用程式設定 Azure 監控

設定 OpenTelemetry 將追蹤和指標從 Java 應用程式匯出至 Azure Monitor,以進行集中式可觀測性

從已棄用匯出器遷移

從已棄用的 azure-monitor-opentelemetry-exporter 移轉至新的 azure-monitor-opentelemetry-autoconfigure 套件

實作分散式追蹤

建立 span、巢狀 span 並記錄例外,以在 Azure 中追蹤跨微服務的要求流程

試試這些提示

基本 Azure Monitor 設定
展示如何在我的 Java 應用程式中設定 Azure Monitor OpenTelemetry 匯出器。我想使用連接字串將追蹤匯出至 Application Insights。
建立自訂 Span
如何在 Java 中建立具有自訂屬性的 OpenTelemetry span 並將其匯出至 Azure Monitor?包含設定屬性和記錄例外的範例。
新增自訂 Span 處理器
建立一個自訂 SpanProcessor,在匯出至 Azure Monitor 之前為每個 span 新增自訂屬性。展示如何向 OpenTelemetry SDK 註冊它。
遷移至 Autoconfigure
從已棄用的 azure-monitor-opentelemetry-exporter 遷移至 azure-monitor-opentelemetry-autoconfigure 的步驟為何?展示所需的相依性變更和程式碼更新。

最佳實務

  • 始終搭配 span.makeCurrent() 使用 try-with-resources 以進行正確的內容管理
  • 使用 recordException() 在 span 上記錄例外,以便在 Azure 中進行錯誤追蹤
  • 遵循 OpenTelemetry 語意慣例進行屬性命名

避免

  • 請勿在原始程式碼中硬式編碼連接字串 - 請使用環境變數
  • 避免建立未結束的 span - 始終呼叫 span.end()
  • 請勿跳過例外記錄 - 始終在 catch 區塊中呼叫 recordException()

常見問題

此套件是否仍有支援?
不,azure-monitor-opentelemetry-exporter 已棄用。請改用 azure-monitor-opentelemetry-autoconfigure。
需要什麼 Java 版本?
Azure Monitor OpenTelemetry 套件需要 Java 8 或更高版本。
如何取得連接字串?
在 Azure Portal 的 Application Insights > 設定 > 連接字串下取得您的連接字串。
我可以將此與 Spring Boot 搭配使用嗎?
可以,autoconfigure 套件與 Spring Boot 自動設定整合。新增相依性並設定連接字串。
這是否支援指標匯出?
可以,OpenTelemetry 指標可以匯出至 Azure Monitor。使用 Meter 建立計數器和直方圖。
匯出器和 autoconfigure 有何差異?
匯出器需要手動設定,而 autoconfigure 則為常見框架提供自動檢測和簡化的設定。