技能 azure-monitor-opentelemetry-ts
📦

azure-monitor-opentelemetry-ts

安全 🔑 环境变量🌐 网络访问

将 Azure Monitor 遥测添加到 Node.js 应用

应用团队需要可观测性来进行生产问题排查和性能监控。本技能为使用 OpenTelemetry 标准对 TypeScript 和 JavaScript 应用进行检测提供完整指南。

支持: Claude Codex Code(CC)
🥉 74 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“azure-monitor-opentelemetry-ts”。 Add Azure Monitor OpenTelemetry to my Express app

预期结果:

使用 npm install @azure/monitor-opentelemetry 安装包,然后在导入 Express 之前导入并调用 useAzureMonitor,传入您的连接字符串。SDK 将自动检测 HTTP 请求、数据库调用和 Azure SDK 操作。

正在使用“azure-monitor-opentelemetry-ts”。 Create a custom span for my database operation

预期结果:

使用 trace.getTracer 获取追踪器,使用操作名称调用 startSpan,设置数据库类型和查询等属性,为处理阶段添加事件,在错误时记录异常,并在 finally 块中调用 end。

安全审计

安全
v1 • 2/25/2026

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
已扫描文件
325
分析行数
3
发现项
1
审计总数
低风险问题 (1)
Documentation Scanned as Code
Static analyzer flagged SKILL.md documentation examples as security issues. All findings are false positives - the file contains TypeScript code examples and bash commands for documentation purposes only.
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
100
安全
91
规范符合性

你能构建什么

生产应用监控

为生产 Node.js API 设置全面遥测,以追踪请求延迟、错误率和依赖项。

微服务分布式追踪

使用 OpenTelemetry 标准上下文传播实现微服务间的端到端追踪可见性。

自定义业务指标

与应用特定指标(如用户操作、功能使用和业务 KPI)以及标准遥测一起追踪。

试试这些提示

基础自动检测设置
帮助我使用默认配置将 Azure Monitor OpenTelemetry 添加到我的 Express.js 应用。
自定义追踪配置
向我展示如何为我的生产应用配置 Azure Monitor OpenTelemetry,包括自定义采样、离线存储和特定检测选项。
手动 Span 创建
我需要使用自定义 span、属性和事件追踪特定操作。向我展示如何创建具有适当错误处理的手动追踪。
自定义指标和处理器
帮助我使用 meter 提供程序设置自定义指标,创建过滤 span 处理器,并为我的应用配置日志导出器。

最佳实践

  • 在导入任何其他模块之前调用 useAzureMonitor,以确保正确的自动检测
  • 将连接字符串存储在环境变量中,切勿放在源代码中
  • 使用 shutdownAzureMonitor 实现优雅关闭,以刷新待处理的遥测数据

避免

  • 不要在应用退出时跳过调用 shutdownAzureMonitor - 遥测数据将丢失
  • 不要在生产中将采样比率设置为 0 - 您将丢失所有遥测数据
  • 不要多次初始化 useAzureMonitor - 这会导致资源冲突

常见问题

最低要求的 Node.js 版本是什么?
需要 Node.js 18.19.0 或更高版本以支持 ESM 加载器。对于 CommonJS,支持 Node.js 14+。
我需要安装单独的导出器吗?
不需要,@azure/monitor-opentelemetry 包含导出器。只有在自定义底层设置时才需要单独安装 @azure/monitor-opentelemetry-exporter。
如何启用 ESM 加载器?
使用 node --import @azure/monitor-opentelemetry/loader 运行您的应用,或将导入添加到您的 package.json 脚本中。
我可以过滤发送到 Azure Monitor 的追踪吗?
是的,使用自定义 span 处理器配合 onEnd 过滤或修改 span,或配置 samplingRatio 选项。
如何为所有遥测添加自定义维度?
使用自定义 span 处理器的 onEnd 方法为 span 添加属性,或在配置 SDK 时使用 resourceFromAttributes。
如果 Azure Monitor 不可用会发生什么?
使用 storageDirectory 选项启用离线存储,在本地缓冲遥测数据并在稍后重试。

开发者详情

文件结构

📄 SKILL.md