azure-monitor-opentelemetry-py 是什么?
azure-monitor-opentelemetry-py 是面向 Python 应用的 Azure Monitor OpenTelemetry Distro,用于集中配置 Application Insights,并自动采集常见 Web、HTTP、数据库和缓存库的遥测。它适合希望快速接入自动埋点的应用;需要自行控制 Exporter / Provider 管线时,应评估低层 exporter Skill。
中文说明由本站依据来源整理;英文原文保留在页面下方。
适合用在
- 希望在 Flask、Django 或 FastAPI 服务中采集请求追踪、依赖调用和异常。
- 需要为多个 Python 服务统一设置 service name、采样比例和 Application Insights 目标。
怎么接入你的 Agent?
- 定位完整 Skill 目录
打开本项目来源,核对
SKILL.md及其引用的脚本和资料。 - 交给你正在用的 Agent
在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。
- 确认识别,再做具体任务
让 Agent 回报安装目录和识别到的名称
azure-monitor-opentelemetry-py,然后按本页使用示例提供材料。
展开并复制给 Codex 的安装指令
安装并检查 azure-monitor-opentelemetry-py
请在 Codex 的当前工作环境中安装并检查 azure-monitor-opentelemetry-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-opentelemetry-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Claude Code 的安装指令
安装并检查 azure-monitor-opentelemetry-py
请在 Claude Code 的当前工作环境中安装并检查 azure-monitor-opentelemetry-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-opentelemetry-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Cursor 的安装指令
安装并检查 azure-monitor-opentelemetry-py
请在 Cursor Agent 的当前工作环境中安装并检查 azure-monitor-opentelemetry-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-opentelemetry-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 当前 Agent 的安装指令
安装并检查 azure-monitor-opentelemetry-py
请在 当前 Agent 的当前工作环境中安装并检查 azure-monitor-opentelemetry-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-opentelemetry-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。装好以后,具体怎么用?
准备哪些材料
- 安装 azure-monitor-opentelemetry,并准备目标 Application Insights connection string;若使用 Microsoft Entra 认证,还需准备 credential 与相应身份权限。
- 确认实际使用的 Python 框架和库是否属于已安装的自动 instrumentations;自动采集范围不能从 Skill 的示例推断为任意库都支持。
会得到什么
- Python 应用的启动初始化位置、接入配置、预期遥测类型与验证查询;列出未覆盖的库及所需手动埋点。
实际使用顺序
- 在应用启动阶段尽早调用 configure_azure_monitor,让自动 instrumentation 在框架和客户端库初始化前完成。
- 通过环境变量读取 Application Insights connection string;生产环境不要把连接信息硬编码进仓库。按部署方式选择采样率、资源属性和需要启用的 instrumentation。
- 在服务中触发一条可识别的请求,分别检查 traces、dependencies、exceptions 或日志是否到达正确 Application Insights 资源;没有数据时检查初始化顺序、采样、凭据与出口网络。
- 进程退出时显式 flush / shutdown telemetry provider,避免短生命周期任务在后台导出完成前退出。
从一个具体任务开始
本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。
复制一个具体任务
教学任务:使用 azure-monitor-opentelemetry-py,为一个 FastAPI 服务拟定 Application Insights 接入步骤。先确认 Python 版本、框架启动入口、目标资源和认证方式;说明 configure_azure_monitor 的初始化时机、采样和关闭时 flush/shutdown 的位置,并列出用一条请求验证 trace、dependency、exception 的办法。只给方案,不声称已运行。预期得到与 FastAPI 启动生命周期匹配的接入清单。此教学任务未安装包、未连接 Application Insights 或验证采集结果。
使用条件与边界
- 源文展示了多种框架示例,但示例并非完整项目;要按当前 SDK 版本和应用生命周期核对初始化及 provider 关闭 API。
- 遥测采样会减少进入后端的数据;看到较少记录不必然表示请求没有发生。Connection string 标识目标资源,凭据认证与资源标识是不同配置职责。
常见问题
调用 configure_azure_monitor 后为什么还看不到请求?
先核对它是否在框架和受监测库初始化之前执行,再确认 connection string 指向的资源、认证权限、采样比例、进程是否正常 flush/shutdown,以及目标表和时间窗口。
来源原文与资料状态
- 源文件
- 已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
- 中文使用说明
- 已针对下方源文件版本整理用途、用法和常见问题
- 安装与任务测试
- 本站未执行安装或任务测试
- 来源复核
- 本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料
.github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z
以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。
抓取成功不代表已完成安装或任务测试。
Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation. Triggers: "azure-monitor-opentelemetry", "configure_azure_monitor", "Application Insights", "OpenTelemetry distro", "auto-instrumentation".
查看源文件章节 / Source sections
- 原文:Azure Monitor OpenTelemetry Distro for Python
- 安装 / Installation
- 原文:Environment Variables
- 原文:Authentication & Lifecycle
- 快速开始 / Quick Start
- 原文:Explicit Connection String
- 原文:With Flask
- 原文:With Django
- 原文:With FastAPI
- 原文:Custom Traces
- 原文:Custom Metrics
- 原文:Custom Logs
- 原文:Sampling
- 原文:Cloud Role Name
- 原文:Disable Specific Instrumentations
- 原文:Enable Live Metrics
- 原文:Azure AD Authentication
- 原文:Auto-Instrumentations Included
- 原文:Configuration Options
- 原文:Best Practices
- 原文:Reference Files
原文:Azure Monitor OpenTelemetry Distro for Python
One-line setup for Application Insights with OpenTelemetry auto-instrumentation.
安装 / Installation
```bash pip install azure-monitor-opentelemetry ```
原文:Environment Variables
```bash APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/ # Required for all auth methods AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production ```
原文:Authentication & Lifecycle
> **🔑 Two rules apply to every code sample below:** > > 1. **Prefer `DefaultAzureCredential` for ingestion auth when supported.** `APPLICATIONINSIGHTS_CONNECTION_STRING` identifies the target Application Insights resource, and `credential=DefaultAzureCredential(...)` provides Microsoft Entra authentication. > - Local dev: `DefaultAzureCredential` works as-is. > - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials. > 2. **Providers are not context managers.** Flush and shut down telemetry providers explicitly at process exit so buffers are exported deterministically. > > Snippets may abbreviate this setup, but production code should always follow both rules.
快速开始 / Quick Start
```python from azure.identity import DefaultAzureCredential from azure.monitor.opentelemetry import configure_azure_monitor # Connection string identifies the App Insights resource (read from APPLICATIONINSIGHTS_CONNECTION_STRING env var). # DefaultAzureCredential authenticates ingestion via Microsoft Entra ID (preferred over instrumentation-key-only auth). configure_azure_monitor( credential=DefaultAzureCredential(), ) # Your application code... ```
原文:Explicit Connection String
Pass the connection string explicitly by reading it from the environment variable. The value includes both `InstrumentationKey` and `IngestionEndpoint`. ```python import os from azure.monitor.opentelemetry import configure_azure_monitor # Read the full connection string from the environment. # Format: "InstrumentationKey=<key>;IngestionEndpoint=https://<id>.in.applicationinsights.azure.com/" connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] try: configure_azure_monitor( connection_string=connection_string, ) # Your application code... except Exception as exc: raise RuntimeError(f"Azure Monitor configuration failed: {exc}") from exc ```
文件 SHA256:5f3da3c631f76fe4a52a159c8eb055e54819eb6fd5269803b4106773a70f98fd
仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。
Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation. Triggers: "azure-monitor-opentelemetry", "configure_azure_monitor", "Application Insights", "OpenTelemetry distro", "auto-instrumentation".
历史收录数据
| 来源仓库 | microsoft/skills |
|---|---|
| Skill源路径 | .github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-py/SKILL.md |
安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。
