[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-9655dcb3-b800-4901-a023-21a706184659":3,"$fQY-KqrY9QcbZWJ8kHXDdTpHuKCt0lTxBsNT5ghHkEPo":42},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":33},"9655dcb3-b800-4901-a023-21a706184659","azure-monitor-ingestion-py","Azure Monitor Python SDK用于摄取。用于通过日志摄取API将自定义日志发送到日志分析工作区。","cat_coding_backend","mod_coding","sickn33,coding","---\nname: azure-monitor-ingestion-py\ndescription: Azure Monitor Ingestion SDK for Python. Use for sending custom logs to Log Analytics workspace via Logs Ingestion API.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure Monitor Ingestion SDK for Python\n\nSend custom logs to Azure Monitor Log Analytics workspace using the Logs Ingestion API.\n\n## Installation\n\n```bash\npip install azure-monitor-ingestion\npip install azure-identity\n```\n\n## Environment Variables\n\n```bash\n# Data Collection Endpoint (DCE)\nAZURE_DCE_ENDPOINT=https:\u002F\u002F\u003Cdce-name>.\u003Cregion>.ingest.monitor.azure.com\n\n# Data Collection Rule (DCR) immutable ID\nAZURE_DCR_RULE_ID=dcr-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n# Stream name from DCR\nAZURE_DCR_STREAM_NAME=Custom-MyTable_CL\n```\n\n## Prerequisites\n\nBefore using this SDK, you need:\n\n1. **Log Analytics Workspace** — Target for your logs\n2. **Data Collection Endpoint (DCE)** — Ingestion endpoint\n3. **Data Collection Rule (DCR)** — Defines schema and destination\n4. **Custom Table** — In Log Analytics (created via DCR or manually)\n\n## Authentication\n\n```python\nfrom azure.monitor.ingestion import LogsIngestionClient\nfrom azure.identity import DefaultAzureCredential\nimport os\n\nclient = LogsIngestionClient(\n    endpoint=os.environ[\"AZURE_DCE_ENDPOINT\"],\n    credential=DefaultAzureCredential()\n)\n```\n\n## Upload Custom Logs\n\n```python\nfrom azure.monitor.ingestion import LogsIngestionClient\nfrom azure.identity import DefaultAzureCredential\nimport os\n\nclient = LogsIngestionClient(\n    endpoint=os.environ[\"AZURE_DCE_ENDPOINT\"],\n    credential=DefaultAzureCredential()\n)\n\nrule_id = os.environ[\"AZURE_DCR_RULE_ID\"]\nstream_name = os.environ[\"AZURE_DCR_STREAM_NAME\"]\n\nlogs = [\n    {\"TimeGenerated\": \"2024-01-15T10:00:00Z\", \"Computer\": \"server1\", \"Message\": \"Application started\"},\n    {\"TimeGenerated\": \"2024-01-15T10:01:00Z\", \"Computer\": \"server1\", \"Message\": \"Processing request\"},\n    {\"TimeGenerated\": \"2024-01-15T10:02:00Z\", \"Computer\": \"server2\", \"Message\": \"Connection established\"}\n]\n\nclient.upload(rule_id=rule_id, stream_name=stream_name, logs=logs)\n```\n\n## Upload from JSON File\n\n```python\nimport json\n\nwith open(\"logs.json\", \"r\") as f:\n    logs = json.load(f)\n\nclient.upload(rule_id=rule_id, stream_name=stream_name, logs=logs)\n```\n\n## Custom Error Handling\n\nHandle partial failures with a callback:\n\n```python\nfailed_logs = []\n\ndef on_error(error):\n    print(f\"Upload failed: {error.error}\")\n    failed_logs.extend(error.failed_logs)\n\nclient.upload(\n    rule_id=rule_id,\n    stream_name=stream_name,\n    logs=logs,\n    on_error=on_error\n)\n\n# Retry failed logs\nif failed_logs:\n    print(f\"Retrying {len(failed_logs)} failed logs...\")\n    client.upload(rule_id=rule_id, stream_name=stream_name, logs=failed_logs)\n```\n\n## Ignore Errors\n\n```python\ndef ignore_errors(error):\n    pass  # Silently ignore upload failures\n\nclient.upload(\n    rule_id=rule_id,\n    stream_name=stream_name,\n    logs=logs,\n    on_error=ignore_errors\n)\n```\n\n## Async Client\n\n```python\nimport asyncio\nfrom azure.monitor.ingestion.aio import LogsIngestionClient\nfrom azure.identity.aio import DefaultAzureCredential\n\nasync def upload_logs():\n    async with LogsIngestionClient(\n        endpoint=endpoint,\n        credential=DefaultAzureCredential()\n    ) as client:\n        await client.upload(\n            rule_id=rule_id,\n            stream_name=stream_name,\n            logs=logs\n        )\n\nasyncio.run(upload_logs())\n```\n\n## Sovereign Clouds\n\n```python\nfrom azure.identity import AzureAuthorityHosts, DefaultAzureCredential\nfrom azure.monitor.ingestion import LogsIngestionClient\n\n# Azure Government\ncredential = DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_GOVERNMENT)\nclient = LogsIngestionClient(\n    endpoint=\"https:\u002F\u002Fexample.ingest.monitor.azure.us\",\n    credential=credential,\n    credential_scopes=[\"https:\u002F\u002Fmonitor.azure.us\u002F.default\"]\n)\n```\n\n## Batching Behavior\n\nThe SDK automatically:\n- Splits logs into chunks of 1MB or less\n- Compresses each chunk with gzip\n- Uploads chunks in parallel\n\nNo manual batching needed for large log sets.\n\n## Client Types\n\n| Client | Purpose |\n|--------|---------|\n| `LogsIngestionClient` | Sync client for uploading logs |\n| `LogsIngestionClient` (aio) | Async client for uploading logs |\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **DCE** | Data Collection Endpoint — ingestion URL |\n| **DCR** | Data Collection Rule — defines schema, transformations, destination |\n| **Stream** | Named data flow within a DCR |\n| **Custom Table** | Target table in Log Analytics (ends with `_CL`) |\n\n## DCR Stream Name Format\n\nStream names follow patterns:\n- `Custom-\u003CTableName>_CL` — For custom tables\n- `Microsoft-\u003CTableName>` — For built-in tables\n\n## Best Practices\n\n1. **Use DefaultAzureCredential** for authentication\n2. **Handle errors gracefully** — use `on_error` callback for partial failures\n3. **Include TimeGenerated** — Required field for all logs\n4. **Match DCR schema** — Log fields must match DCR column definitions\n5. **Use async client** for high-throughput scenarios\n6. **Batch uploads** — SDK handles batching, but send reasonable chunks\n7. **Monitor ingestion** — Check Log Analytics for ingestion status\n8. **Use context manager** — Ensures proper client cleanup\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,158,2007,"2026-05-16 13:07:12",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":25,"skillCount":32,"createdAt":26},"后端开发","backend","mdi-server","API、数据库、服务端架构",296,[34],{"id":35,"skillId":4,"version":36,"fileName":37,"fileSize":38,"filePath":39,"fileHash":40,"manifest":41,"createdAt":19},"6d750555-fb7b-4944-a4f0-40fca4ddf40e","1.0.0","azure-monitor-ingestion-py.zip",2211,"uploads\u002Fskills\u002F9655dcb3-b800-4901-a023-21a706184659\u002Fazure-monitor-ingestion-py.zip","07a61dcc3ec206e34f922b60882aec06cd734d953071914bcea84a251996994e","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":5720}]",{"code":43,"message":44,"data":45},200,"success",{"items":46,"stats":47,"page":50},[],{"averageRating":48,"totalRatings":48,"ratingCounts":49},0,[48,48,48,48,48],{"limit":51,"offset":48,"hasMore":52,"nextOffset":51,"ratedOnly":16},15,false]