Azure Monitor OpenTelemetry Exporter for Java
将 OpenTelemetry 数据导出到 Azure Monitor
此技能帮助 Java 开发人员将 OpenTelemetry 追踪、指标和日志导出到 Azure Monitor 和 Application Insights。它提供了已弃用导出器包的代码示例,以及迁移到推荐的 autoconfigure 解决方案的指导。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“Azure Monitor OpenTelemetry Exporter for Java”。 Show me how to set up Azure Monitor OpenTelemetry Exporter in my Java application
预期结果:
要在 Java 中设置 Azure Monitor OpenTelemetry 导出器,请在 pom.xml 中添加 autoconfigure 依赖项并配置连接字符串。推荐的方法是使用 azure-monitor-opentelemetry-autoconfigure,而不是已弃用的导出器。设置 APPLICATIONINSIGHTS_CONNECTION_STRING 环境变量,并使用 AutoConfiguredOpenTelemetrySdk.builder() 初始化 SDK。
正在使用“Azure Monitor OpenTelemetry Exporter for Java”。 How do I create spans with custom attributes for Azure Monitor?
预期结果:
从 OpenTelemetry 获取 Tracer,使用 tracer.spanBuilder() 创建跨度,使用 setAttribute() 设置属性,并确保在 finally 块中调用 span.end()。将 makeCurrent() 与 try-with-resources 结合使用,以实现正确的上下文传播。在 Azure 中进行错误跟踪时,使用 span.recordException() 记录异常。
安全审计
安全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.
质量评分
你能构建什么
为 Java 应用设置 Azure 监控
配置 OpenTelemetry 将追踪和指标从 Java 应用程序导出到 Azure Monitor,以实现集中式可观测性
从弃用的导出器迁移
从已弃用的 azure-monitor-opentelemetry-exporter 迁移到新的 azure-monitor-opentelemetry-autoconfigure 包
实现分布式追踪
创建跨度、嵌套跨度并记录异常,以在 Azure 中跨微服务追踪请求流
试试这些提示
展示如何在 Java 应用程序中设置 Azure Monitor OpenTelemetry 导出器。我想使用连接字符串将追踪导出到 Application Insights。
如何在 Java 中创建具有自定义属性的 OpenTelemetry 跨度并导出到 Azure Monitor?请包含设置属性和记录异常的示例。
创建一个自定义 SpanProcessor,用于在导出到 Azure Monitor 之前向每个跨度添加自定义属性。展示如何将其注册到 OpenTelemetry SDK。
从弃用的 azure-monitor-opentelemetry-exporter 迁移到 azure-monitor-opentelemetry-autoconfigure 的步骤是什么?请展示所需的依赖更改和代码更新。
最佳实践
- 始终将 span.makeCurrent() 与 try-with-resources 结合使用,以实现正确的上下文管理
- 使用 recordException() 在跨度上记录异常,以便在 Azure 中进行错误跟踪
- 遵循 OpenTelemetry 语义约定进行属性命名
避免
- 不要在源代码中硬编码连接字符串 - 使用环境变量
- 避免创建不结束的跨度 - 始终调用 span.end()
- 不要跳过异常记录 - 在 catch 块中始终调用 recordException()