azure-monitor-ingestion-py 是什么?
azure-monitor-ingestion-py 用 Python LogsIngestionClient 将自定义日志经 Logs Ingestion API 发送到 Azure Monitor。与 OpenTelemetry 自动采集不同,它要求目标 DCE、DCR immutable ID、stream name 和字段 schema 对齐,适用于把已有业务记录写入 Log Analytics 自定义表。
中文说明由本站依据来源整理;英文原文保留在页面下方。
适合用在
- 应用已生成业务审计或设备记录,需要通过 Logs Ingestion API 写入自定义 Log Analytics 表。
- 需要处理批量上传、部分失败回调或在异步任务中发送日志。
怎么接入你的 Agent?
- 定位完整 Skill 目录
打开本项目来源,核对
SKILL.md及其引用的脚本和资料。 - 交给你正在用的 Agent
在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。
- 确认识别,再做具体任务
让 Agent 回报安装目录和识别到的名称
azure-monitor-ingestion-py,然后按本页使用示例提供材料。
展开并复制给 Codex 的安装指令
安装并检查 azure-monitor-ingestion-py
请在 Codex 的当前工作环境中安装并检查 azure-monitor-ingestion-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-ingestion-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Claude Code 的安装指令
安装并检查 azure-monitor-ingestion-py
请在 Claude Code 的当前工作环境中安装并检查 azure-monitor-ingestion-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-ingestion-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Cursor 的安装指令
安装并检查 azure-monitor-ingestion-py
请在 Cursor Agent 的当前工作环境中安装并检查 azure-monitor-ingestion-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-ingestion-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 当前 Agent 的安装指令
安装并检查 azure-monitor-ingestion-py
请在 当前 Agent 的当前工作环境中安装并检查 azure-monitor-ingestion-py 这个 Skill。
项目身份:microsoft/skills / azure-monitor-ingestion-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。装好以后,具体怎么用?
准备哪些材料
- 安装 azure-monitor-ingestion 与 azure-identity;准备 DCE endpoint、DCR immutable ID、DCR stream name、目标工作区/表以及允许该身份写入的权限。
- 待上传记录的字段和类型须符合 DCR stream/schema 及转换规则;TimeGenerated 通常是源文强调的必要时间字段。
会得到什么
- DCE/DCR/stream 配置映射、字段 schema、上传记录的数量与失败记录,以及写入后查询的验证条件。
实际使用顺序
- 先在 Azure 配好 DCE、DCR 和目标表,确认 immutable ID 与 stream name,而不是把普通 workspace ID 当成 rule ID。
- 使用 LogsIngestionClient 建立连接,通过 upload(rule_id, stream_name, logs) 上传结构化记录;SDK 文档描述其会按不超过 1 MB 的块拆分并并行传送。
- 把 on_error 回调里的失败记录和错误信息保留下来,按失败范围决定是否重试;不要使用静默忽略错误的示例做生产处理。
- 上传后用 Logs Query 查询目标表的 TimeGenerated 和样例字段,区分上传调用未报错与数据最终可查询这两个检查点。
从一个具体任务开始
本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。
复制一个具体任务
教学任务:使用 azure-monitor-ingestion-py 规划将一条订单审计记录写入 Azure Monitor 自定义表。先列出必须从 Azure 管理员取得的 DCE endpoint、DCR immutable ID、stream name、schema 和身份权限;再给出含 TimeGenerated 的记录形状、upload 调用要点、on_error 处理和写入后的查询验证。只给教学方案,不声称上传成功。预期得到一条可映射到既有 DCR schema 的上传方案。此教学任务未创建 DCR、未安装 SDK,也未上传数据。
使用条件与边界
- SKILL.md 里有
...和占位 endpoint 等非完整代码;其批处理描述不能替代目标 DCR 的大小、配额、频率和吞吐限制核验。 - 源文提供了静默忽略 upload error 的反例;生产流程必须记录错误。对于网络结果不确定的重试,需要评估重复写入可能性,不能把重试等同于 exactly-once。
常见问题
DCE、DCR 和 stream name 分别是什么?
DCE 提供摄取 endpoint,DCR 定义字段处理和路由,stream name 选择 DCR 中的数据流。三者需要匹配目标表;仅有 workspace ID 不能替代这组摄取配置。
来源原文与资料状态
- 源文件
- 已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
- 中文使用说明
- 已针对下方源文件版本整理用途、用法和常见问题
- 安装与任务测试
- 本站未执行安装或任务测试
- 来源复核
- 本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料
.github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z
以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。
抓取成功不代表已完成安装或任务测试。
Azure Monitor Ingestion SDK for Python. Use for sending custom logs to Log Analytics workspace via Logs Ingestion API. Triggers: "azure-monitor-ingestion", "LogsIngestionClient", "custom logs", "DCR", "data collection rule", "Log Analytics".
查看源文件章节 / Source sections
- 原文:Azure Monitor Ingestion SDK for Python
- 安装 / Installation
- 原文:Environment Variables
- 前置条件 / Prerequisites
- 原文:Authentication & Lifecycle
- 原文:Upload Custom Logs
- 原文:Upload from JSON File
- 原文:Custom Error Handling
- 原文:Ignore Errors
- 原文:Async Client
- 原文:Sovereign Clouds
- 原文:Batching Behavior
- 原文:Client Types
- 原文:Key Concepts
- 原文:DCR Stream Name Format
- 原文:Best Practices
- 原文:Reference Files
原文:Azure Monitor Ingestion SDK for Python
Send custom logs to Azure Monitor Log Analytics workspace using the Logs Ingestion API.
安装 / Installation
```bash pip install azure-monitor-ingestion pip install azure-identity ```
原文:Environment Variables
```bash # Data Collection Endpoint (DCE) AZURE_DCE_ENDPOINT=https://<dce-name>.<region>.ingest.monitor.azure.com # Required for all auth methods # Data Collection Rule (DCR) immutable ID AZURE_DCR_RULE_ID=dcr-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Required for all auth methods # Stream name from DCR AZURE_DCR_STREAM_NAME=Custom-MyTable_CL # Required for all auth methods AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production ```
前置条件 / Prerequisites
Before using this SDK, you need: 1. **Log Analytics Workspace** — Target for your logs 2. **Data Collection Endpoint (DCE)** — Ingestion endpoint 3. **Data Collection Rule (DCR)** — Defines schema and destination 4. **Custom Table** — In Log Analytics (created via DCR or manually)
原文:Authentication & Lifecycle
> **🔑 Two rules apply to every code sample below:** > > 1. **Prefer `DefaultAzureCredential`.** It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation. > - 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. **Wrap every client in a context manager** so HTTP transports, sockets, and token caches are released deterministically: > - Sync: `with <Client>(...) as client:` > - Async: `async with <Client>(...) as client:` **and** `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`) > > Snippets may abbreviate this setup, but production code should always follow both rules. ```python from azure.monitor.ingestion import LogsIngestionClient from azure.identity import DefaultAzureCredential, ManagedIdentityCredential import os # Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential> credential = DefaultAzureCredential(require_envvar=True) # Or use a specific credential directly in production: # See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes # credential = ManagedIdentityCredential() with LogsIngestionClient( endpoint=os.environ["AZURE_DCE_ENDPOINT"], credential=credential ) as client: # Use `client.upload(...)` for all subsequent operations (see examples below) ... ```
原文:Upload Custom Logs
```python from azure.monitor.ingestion import LogsIngestionClient from azure.identity import DefaultAzureCredential import os rule_id = os.environ["AZURE_DCR_RULE_ID"] stream_name = os.environ["AZURE_DCR_STREAM_NAME"] logs = [ {"TimeGenerated": "2024-01-15T10:00:00Z", "Computer": "server1", "Message": "Application started"}, {"TimeGenerated": "2024-01-15T10:01:00Z", "Computer": "server1", "Message": "Processing request"}, {"TimeGenerated": "2024-01-15T10:02:00Z", "Computer": "server2", "Message": "Connection established"} ] with LogsIngestionClient( endpoint=os.environ["AZURE_DCE_ENDPOINT"], credential=DefaultAzureCredential() ) as client: client.upload(rule_id=rule_id, stream_name=stream_name, logs=logs) ```
文件 SHA256:e9686a6ef133b735704d1f677fb926857a056b8b1bb80e085d495d9136c52eae
仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。
Azure Monitor Ingestion SDK for Python. Use for sending custom logs to Log Analytics workspace via Logs Ingestion API. Triggers: "azure-monitor-ingestion", "LogsIngestionClient", "custom logs", "DCR", "data collection rule", "Log Analytics".
历史收录数据
| 来源仓库 | microsoft/skills |
|---|---|
| Skill源路径 | .github/plugins/azure-sdk-python/skills/azure-monitor-ingestion-py/SKILL.md |
安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。
