microsoft/skills

azure-monitor-opentelemetry-tsmicrosoft/skills

在 Node.js 启动时初始化遥测并验证导出

  • SKILL.md 已保存
  • 中文用法已整理
  • 安装与运行未实测
先判断是否解决你的问题

azure-monitor-opentelemetry-ts 是什么?

azure-monitor-opentelemetry-ts 面向 Node.js 服务,通过 @azure/monitor-opentelemetry 自动采集 traces、metrics 和 logs,并允许补充自定义 Span、采样、资源属性及优雅关闭。Skill 同时介绍低层 Exporter 和 Logs Ingestion,但它们对应更细的管线控制或自定义日志写入,不应与自动埋点方案混为一谈。

中文说明由本站依据来源整理;英文原文保留在页面下方。

适合用在

  • 需要为 Node.js 服务快速接入 Application Insights 自动埋点。
  • 需要在 ESM 项目、容器或无服务器进程中明确初始化顺序和退出时的遥测刷新。
按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 azure-monitor-opentelemetry-ts,然后按本页使用示例提供材料。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 azure-monitor-opentelemetry-ts

请在 Codex 的当前工作环境中安装并检查 azure-monitor-opentelemetry-ts 这个 Skill。

项目身份:microsoft/skills / azure-monitor-opentelemetry-ts
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
准备输入,再按步骤执行

装好以后,具体怎么用?

准备哪些材料

  • 安装 @azure/monitor-opentelemetry,准备 Application Insights connection string,并确认 Node.js 版本、ESM/CJS 模式、构建产物入口和实际框架。
  • 若项目依赖自动 instrumentation,需检查具体依赖是否受支持;若只要上传自定义表日志,则应另评估 Logs Ingestion API、DCR、DCE 与 stream。

会得到什么

  • 符合当前模块系统的启动命令、遥测配置与关闭钩子,以及可用于确认 trace、metric 和 log 的验证步骤。

实际使用顺序

  1. 在应用入口之前初始化 Azure Monitor。CommonJS 可先初始化再加载应用;ESM 静态 import 会先于模块顶层语句求值,不能仅靠把 useAzureMonitor 写在静态 import 语句上方保证顺序。
  2. 对于源文列出的 Node.js 18.19+ ESM 场景,按其 loader 路径配置 node --import @azure/monitor-opentelemetry/loader ./dist/index.js;也可通过动态 import 确保应用模块在初始化后加载,并按当前包版本核对方式。
  3. 配置 connection string、service.name、采样和 instrumentation;在一条真实请求上检查 trace 与依赖调用是否落入正确资源。
  4. 在 SIGTERM 等关闭路径调用 shutdownAzureMonitor,并等待导出完成后再退出;否则短暂任务可能在缓冲数据发送前结束。
使用示例

从一个具体任务开始

本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。

安装并识别 Skill 后发送

复制一个具体任务

教学任务:使用 azure-monitor-opentelemetry-ts,为 Node.js 18.19+ 的 ESM Express 服务设计 Application Insights 初始化。明确指出 ESM 静态 import 的求值顺序,选择 loader 或动态 import 方案;补上 connection string、SIGTERM shutdown 和一条请求的验证路径。请将包版本与运行验证列为待核对,不声称已实际部署。
预期结果

预期得到适配 ESM 启动链的方案,并避免初始化发生在 instrumentation 依赖加载之后。此教学任务未安装或运行 Node.js 应用。

使用前先看这些限制

使用条件与边界

  • 源文的 quick start 先静态 import useAzureMonitor,再以示意注释表示导入 Express;ESM 静态导入实际会先求值,因此这段展示不能直接证明初始化早于其他静态依赖。
  • Exporter API、OpenTelemetry SDK provider API 和 Node loader 对版本有兼容要求;按当前项目依赖锁文件核对,不把源文所有高级配置代码视为同一版本下已验证。
针对这个 Skill 的疑问

常见问题

把 useAzureMonitor 放在 import express 之前就够了吗?

如果两者都是 ESM 静态 import,不够。静态依赖会在模块正文执行前求值。应采用来源所述的 Node loader,或在初始化后再动态加载应用入口,并结合当前包文档验证。

需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
中文使用说明
已针对下方源文件版本整理用途、用法和常见问题
安装与任务测试
本站未执行安装或任务测试
来源复核
本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料

.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 description(原文)

Instrument applications with Azure Monitor and OpenTelemetry for JavaScript (@azure/monitor-opentelemetry). Use when adding distributed tracing, metrics, and logs to Node.js applications with Application Insights.

查看源文件章节 / Source sections
  • 原文:Azure Monitor OpenTelemetry SDK for TypeScript
  • 安装 / Installation
  • 原文:Environment Variables
  • 原文:Quick Start (Auto-Instrumentation)
  • 原文:ESM Support (Node.js 18.19+)
  • 原文:Full Configuration
  • 原文:Custom Traces
  • 原文:Custom Metrics
  • 原文:Manual Exporter Setup
  • 原文:Trace Exporter
  • 原文:Metric Exporter
  • 原文:Log Exporter
  • 原文:Custom Logs Ingestion
  • 原文:Custom Span Processor
  • 原文:Sampling
  • 原文:Shutdown
  • 原文:Key Types
  • 原文:Best Practices
原文:Azure Monitor OpenTelemetry SDK for TypeScript

Auto-instrument Node.js applications with distributed tracing, metrics, and logs.

安装 / Installation

```bash # Distro (recommended - auto-instrumentation) npm install @azure/monitor-opentelemetry # Low-level exporters (custom OpenTelemetry setup) npm install @azure/monitor-opentelemetry-exporter # Custom logs ingestion npm install @azure/monitor-ingestion ```

原文:Environment Variables

```bash APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=... AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production ```

原文:Quick Start (Auto-Instrumentation)

**IMPORTANT:** Call `useAzureMonitor()` BEFORE importing other modules. ```typescript import { useAzureMonitor } from "@azure/monitor-opentelemetry"; useAzureMonitor({ azureMonitorExporterOptions: { connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING } }); // Now import your application import express from "express"; const app = express(); ```

原文:ESM Support (Node.js 18.19+)

```bash node --import @azure/monitor-opentelemetry/loader ./dist/index.js ``` **package.json:** ```json { "scripts": { "start": "node --import @azure/monitor-opentelemetry/loader ./dist/index.js" } } ```

原文:Full Configuration

```typescript import { useAzureMonitor, AzureMonitorOpenTelemetryOptions } from "@azure/monitor-opentelemetry"; import { resourceFromAttributes } from "@opentelemetry/resources"; const options: AzureMonitorOpenTelemetryOptions = { azureMonitorExporterOptions: { connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING, storageDirectory: "/path/to/offline/storage", disableOfflineStorage: false }, // Sampling samplingRatio: 1.0, // 0-1, percentage of traces // Features enableLiveMetrics: true, enableStandardMetrics: true, enablePerformanceCounters: true, // Instrumentation libraries instrumentationOptions: { azureSdk: { enabled: true }, http: { enabled: true }, mongoDb: { enabled: true }, mySql: { enabled: true }, postgreSql: { enabled: true }, redis: { enabled: true }, bunyan: { enabled: false }, winston: { enabled: false } }, // Custom resource resource: resourceFromAttributes({ "service.name": "my-service" }) }; useAzureMonitor(options); ```

文件 SHA256:330aa4ea6110ffca30ef3a8e227d60fe6a3e44ee44b25560b1b5aade427dc476

仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。

SKILL.md原文description · 2026-11-16T12:36:35.145Z

Instrument applications with Azure Monitor and OpenTelemetry for JavaScript (@azure/monitor-opentelemetry). Use when adding distributed tracing, metrics, and logs to Node.js applications with Application Insights.

查看历史简介来源

历史收录数据

来源仓库microsoft/skills
Skill源路径.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md

安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源