本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
常見的處理器使用案例
以下是合併處理器的常見案例和範例組態。
記錄管道範例
範例標準化日誌格式並新增中繼資料
剖析 JSON 日誌、標準化欄位名稱,以及新增環境資訊:
processor: - parse_json: {} - rename_keys: entries: - from_key: "timestamp" to_key: "@timestamp" - from_key: "log_level" to_key: "level" - add_entries: entries: - key: "environment" value: "production" - key: "application" value: "payment-service"
範例清除和標準化欄位值
標準化狀態碼並移除敏感資料:
processor: - uppercase_string: with_keys: ["status", "method"] - delete_entries: with_keys: ["credit_card", "password"] - substitute_string: entries: - source: "status" from: "SUCCESS" to: "OK"
範例擷取和轉換特定欄位
擷取用於分析的使用者資訊和格式:
processor: - extract_value: entries: - source: "user_agent" target: "browser" from: "(?<browser>Chrome|Firefox|Safari)" to: "${browser}" - lowercase_string: with_keys: ["browser"] - move_keys: entries: - from_key: "browser" to_key: "user_data.browser"
範例具有入門級條件的條件式處理
使用入門級when條件根據日誌嚴重性新增不同的中繼資料:
processor: - add_entries: entries: - key: "alert_level" value: "critical" when: "log.level == 'ERROR'" - key: "alert_level" value: "info" when_else: "log.level == 'ERROR'"
範例捨棄不需要的日誌項目
從第三方來源篩選除錯和追蹤日誌項目,以減少雜訊和儲存成本:
processor: - drop_events: when: "log.level in {'DEBUG', 'TRACE'}" handle_expression_failure: "skip"
範例具有 delete_entries 的處理器層級條件式
僅在環境為生產環境時移除敏感欄位:
processor: - delete_entries: with_keys: ["password", "api_key", "ssn"] when: "environment in {'prod', 'staging'}"
指標管道範例
下列範例顯示指標管道的處理器組態。指標處理器使用 OTTL 路徑表達式來鎖定不同範圍內的屬性。
範例將業務內容新增至指標
將團隊擁有權和環境標籤新增至指標資料點:
processor: - add_attributes: attributes: - key: resource.attributes["team"] value: "platform-engineering" - key: resource.attributes["cost_center"] value: "CC-1234"
範例移除高基數屬性
增加儲存成本的 Strip 屬性。不適用於累積指標或已取代的指標 - 如果選取條件中的任何指標具有不支援的時間性,管道會發出UnsupportedTemporality警告指標,您可以在AWS/Observability Admin命名空間中監控:
processor: - delete_attributes: with_keys: - resource.attributes["host.id"] - datapoint.attributes["http.request.id"]
範例標準化命名慣例
重新命名指標和屬性以符合 OpenTelemetry 語意慣例。不適用於累積指標或付費指標:
processor: - rename_metrics: metrics: - from: "cpu_usage_percent" to: "system.cpu.utilization" - rename_attributes: attributes: - from_key: resource.attributes["hostname"] to_key: resource.attributes["host.name"]