dd-logs
作者: datadog-labs
日誌管理 - 搜尋、管道、歸檔與成本控制。
npx skills add https://github.com/datadog-labs/pup --skill dd-logsDatadog Logs
Search, process, and archive logs with cost awareness.
Prerequisites
Datadog Pup (dd-pup/pup) should already be installed:
cargo install --git https://github.com/DataDog/pup
Quick Start
pup auth login
Search Logs
# Basic search
pup logs search --query="status:error" --from="1h"
# With filters
pup logs search --query="service:api status:error" --from="1h" --limit 100
# JSON output is the default
pup logs search --query="@http.status_code:>=500" --from="1h"
Search Syntax
| Query | Meaning |
|---|---|
error | Full-text search |
status:error | Tag equals |
@http.status_code:500 | Attribute equals |
@http.status_code:>=400 | Numeric range |
service:api AND env:prod | Boolean |
@message:*timeout* | Wildcard |
Pipelines
Process logs before indexing:
# List pipelines
pup obs-pipelines list
# Create pipeline (JSON)
pup obs-pipelines create --file pipeline.json
Common Processors
{
"name": "API Logs",
"filter": {"query": "service:api"},
"processors": [
{
"type": "grok-parser",
"name": "Parse nginx",
"source": "message",
"grok": {"match_rules": "%{IPORHOST:client_ip} %{DATA:method} %{DATA:path} %{NUMBER:status}"}
},
{
"type": "status-remapper",
"name": "Set severity",
"sources": ["level", "severity"]
},
{
"type": "attribute-remapper",
"name": "Remap user_id",
"sources": ["user_id"],
"target": "usr.id"
}
]
}
⚠️ Exclusion Filters (Cost Control)
Index only what matters:
{
"name": "Drop debug logs",
"filter": {"query": "status:debug"},
"is_enabled": true
}
High-Volume Exclusions
# Find noisiest log sources
pup logs search --query="*" --from="1h" | jq 'group_by(.service) | map({service: .[0].service, count: length}) | sort_by(-.count)[:10]'
| Exclude | Query |
|---|---|
| Health checks | @http.url:"/health" OR @http.url:"/ready" |
| Debug logs | status:debug |
| Static assets | @http.url:*.css OR @http.url:*.js |
| Heartbeats | @message:*heartbeat* |
Archives
Store logs cheaply for compliance:
# List archives
pup logs archives list
# Archive config (S3 example)
{
"name": "compliance-archive",
"query": "*",
"destination": {
"type": "s3",
"bucket": "my-logs-archive",
"path": "/datadog"
},
"rehydration_tags": ["team:platform"]
}
Log-Based Metrics
Inspect log-based metrics:
# List existing log-based metrics
pup logs metrics list
⚠️ Cardinality warning: Group by bounded values only.
Sensitive Data
Scrubbing Rules
{
"type": "hash-remapper",
"name": "Hash emails",
"sources": ["email", "@user.email"]
}
Never Log
# In your app - sanitize before sending
import re
def sanitize_log(message: str) -> str:
# Remove credit cards
message = re.sub(r'\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b', '[REDACTED]', message)
# Remove SSNs
message = re.sub(r'\b\d{3}-\d{2}-\d{4}\b', '[REDACTED]', message)
return message
Troubleshooting
| Problem | Fix |
|---|---|
| Logs not appearing | Check agent, pipeline filters |
| High costs | Add exclusion filters |
| Search slow | Narrow time range, use indexes |
| Missing attributes | Check grok parser |
References/Documentation
來自 datadog-labs 的更多技能
agent-install
datadog-labs
agent-install — 一個可安裝的 AI 代理技能,由 datadog-labs/agent-skills 發布。
official
agent-skills
datadog-labs
專為AI代理設計的Datadog技能。提供必要的監控、日誌記錄、追蹤與可觀測性功能。
official
dd-apm
datadog-labs
APM - 安裝、入門、儀器化、啟用、設定、配置、追蹤、服務、相依性、效能分析。用於任何涉及 Datadog APM 的請求…
official
dd-audit
datadog-labs
稽核軌跡調查——誰變更了什麼、金鑰遭入侵、成本飆升的根本原因、合規證據(SOC 2/PCI),以及AI活動稽核。
official
dd-audit-ai-activity
datadog-labs
稽核 Bits AI 助手(MCP 伺服器)在您的 Datadog 組織中所執行的操作 — 按使用者分類的工具呼叫、存取的資源,以及用於 AI 治理的異常標記。
official
dd-audit-compliance-report
datadog-labs
從 Datadog Audit Trail 生成符合 SOC 2 和 PCI DSS 的稽核證據,將框架控制項對應至特定查詢模式,並產出…
official
dd-audit-cost-spike-investigation
datadog-labs
調查 Datadog 產品用量或成本異常飆升,透過關聯用量計量資料(何時/何項目飆升)與稽核軌跡設定變更(誰變更了哪些設定…)
official
dd-audit-key-compromise
datadog-labs
調查可能遭入侵的 Datadog API 金鑰 — 動作時間軸、地理位置/IP 分析、呼叫的端點、異常標記及補救步驟。
official