フィルター プロセッサは、OTTL (OpenTelemetry Transformation Language) ブール式に基づいてテレメトリー レコードまたは特定のプロパティを削除します。 これを使用して、テスト データ、デバッグ ログ、ヘルス チェック、または低価値のテレメトリーをネットワークから離れる前に削除します。
フィルタープロセッサを使用する場合
次の場合にフィルター プロセッサを使用します。
- 個人情報またはテスト環境データの削除: ネットワークから流出すべきでないデータを削除します
- 本番環境からデバッグレベルのログを削除する: 重大度でフィルタリングしてノイズを減らす
- ヘルスチェックrequestsをフィルタリングする: 反復的で価値の低い監視トラフィックをドロップする
- 特定のプレフィックスまたはパターンを持つメトリクスを削除: 不要なメトリクス ストリームを削除します
- プロパティに基づいて価値の低いテレメトリーを削除: サービス名、環境、またはカスタム タグでフィルターします。
フィルタープロセッサの仕組み
フィルタ プロセッサは、各テレメトリ レコードに対して OTTL ブール式を評価します。 条件がtrueと評価されると、レコードは削除されます。
これは、 WHERE status = 'ERROR' 「エラーを保持する」ことを意味する多くのクエリ言語とは逆です。フィルタ プロセッサでは、 status == 'ERROR' 「エラーをドロップする」ことを意味します。
構成
パイプラインにフィルター プロセッサを追加します。
filter/Logs: description: Apply drop rules and data processing for logs config: error_mode: ignore rules: - name: drop the log records description: drop all records which has severity text INFO conditions: - log.severity_text == "INFO"設定フィールド:
rules: 順番に評価されるフィルタリングルールの配列。name: ルール識別子。context: 評価するデータのタイプ。サポートされる値:log、span、span_event、metric、datapoint。conditions: OTTLブール式のリスト。
複数の条件: 配列に複数の式を指定すると、それらは OR ロジックで評価されます。いずれかの条件が真の場合、レコードは削除されます。
OTTLブール演算子
比較演算子
==- 等しい!=- 等しくない<- 未満<=- 以下>- より大きい>=- より大きいか等しい
論理演算子
and- 両方の条件が満たされている必要がありますor- いずれかの条件が満たされている必要がありますnot- 条件を否定する
パターンマッチング
IsMatch- 正規表現パターンマッチング
rules: - name: match-health-logs conditions: - 'IsMatch(body, ".*health.*") or IsMatch(attributes["http.url"], ".*\\/api\\/v1\\/health.*")'完全な例
例1: 落下試験環境データ
テスト環境と開発環境からすべてのテレメトリを削除します。
config: rules: - name: drop-test-environment description: Drop logs from test environment conditions: - 'resource.attributes["environment"] == "test"' context: log - name: drop-dev-environment description: Drop logs from dev environment conditions: - 'resource.attributes["environment"] == "dev"' context: log例2: 本番環境でデバッグログを削除する
本番環境では意味のあるログレベルのみを保持します。
config: rules: - name: drop-debug-logs description: Drop all DEBUG severity logs conditions: - 'severity_text == "DEBUG"' context: log - name: drop-low-severity-logs description: Drop INFO and below severity logs conditions: - "severity_number < 9" context: log重大度番号参照:
- トレース = 1-4
- デバッグ = 5-8
- 情報 = 9-12
- 警告 = 13-16
- エラー = 17-20
- 致命的 = 21-24
例3: ヘルスチェックスパンを削除する
診断価値を追加しないヘルスチェック トラフィックを削除します。
config: rules: - name: drop-health-endpoint description: Drop spans from /health endpoint conditions: - 'attributes["http.path"] == "/health"' context: span - name: drop-health-check-spans description: Drop spans named health_check conditions: - 'name == "health_check"' context: span例4: サービス名でドロップする
特定のサービスまたはサービス パターンをフィルターします。
config: rules: - name: drop-legacy-api description: Drop logs from legacy API v1 service conditions: - 'resource.attributes["service.name"] == "legacy-api-v1"' context: log - name: drop-canary-services description: Drop logs from canary deployment services conditions: - 'IsMatch(resource.attributes["service.name"], ".*-canary")' context: log例 5: 特定のプレフィックスを持つメトリクスを削除する
不要なメトリクス ストリームを削除します。
config: rules: - name: drop-internal-metrics description: Drop metrics with internal prefix conditions: - 'IsMatch(name, "^internal\\.")' context: metric - name: drop-debug-datapoints description: Drop datapoints marked as debug type conditions: - 'attributes["metric.type"] == "debug"' context: datapoint例6: ANDを使用した条件の組み合わせ
複数の条件が満たされる場合にのみドロップします。
config: rules: - name: drop-debug-logs-from-test description: Drop DEBUG logs from background-worker service in test environment conditions: - 'severity_text == "DEBUG"' - 'resource.attributes["service.name"] == "background-worker"' - 'resource.attributes["environment"] == "test"' context: log例7: エラーを保持し、その他はすべて削除する
ロジックを反転して、貴重なデータのみを保持します。
config: rules: - name: drop-non-error-logs description: Drop everything below ERROR severity level conditions: - "severity_number < 17" context: logまたは NOT ロジックを使用します。
filter/Logs: description: "Drop non-errors" config: error_mode: ignore rules: - name: drop-non-error-logs description: Drop logs that are not ERROR or FATAL conditions: - 'not (severity_text == "ERROR" or severity_text == "FATAL")' context: log例8: ログ本文のパターンマッチング
特定のパターンを含むログをドロップします。
config: rules: - name: drop-health-check-logs description: Drop logs with health check in body conditions: - 'IsMatch(body, ".*health check.*")' context: log例9: 大量で価値の低いスパンを削除する
頻繁に発生するがあまり価値のないスパンを削除します。
config: rules: - name: drop-fast-cache-hits description: Drop cache hit operations faster than 1ms conditions: - 'attributes["db.operation"] == "get"' - 'end_time_unix_nano - start_time_unix_nano < 1000000' - 'attributes["cache.hit"] == true' context: span例10: HTTPステータスに基づいてドロップする
成功したrequestsフィルタリングし、エラーを保持します:
config: rules: - name: drop-successful-requests description: Drop HTTP requests with status code less than 400 conditions: - 'attributes["http.status_code"] < 400' context: span例11: ORを使用した複数条件
いずれかの条件に一致する場合はドロップします:
config: rules: - name: drop-test-health-debug description: Drop logs from test environment, health checks, or debug severity conditions: - 'resource.attributes["environment"] == "test"' - 'IsMatch(body, ".*health.*")' - 'severity_text == "DEBUG"' context: logデータのドロップと属性のドロップ
フィルター プロセッサは、レコード全体を削除したり (上記を参照)、保持されているレコードから特定の属性を削除したりできます。
レコードを保持したまま属性を削除するには、フィルター プロセッサではなく、変換プロセッサのdelete_key()関数を使用する必要があります。フィルター プロセッサはレコード全体のみを削除します。
間違ったアプローチ(これは機能しません):
filter/Logs: config: rules: - name: wrong-attribute-drop description: Identify and drop logs containing specific sensitive attributes conditions: - 'delete attributes["sensitive_field"]' # Filter conditions must be boolean, not actions context: log正しいアプローチ(代わりに変換プロセッサを使用する):
transform/Logs: description: "Remove sensitive attribute" config: rules: - name: remove-sensitive-field description: "Redacts the 'sensitive_field' attribute from log records to ensure privacy compliance." statements: - 'delete_key(attributes, "sensitive_field")' output: - nrexporter/newrelicパフォーマンスに関する考慮事項
- 順序が重要: フィルタープロセッサをパイプラインの早い段階に配置して、高価な処理の前に不要なデータを削除します。
- 条件を組み合わせる: 複数のフィルター プロセッサを連結するのではなく、単一の式で
and/orロジックを使用します。 - 正規表現のパフォーマンス:
IsMatchは完全一致チェックよりもコストがかかります。可能な場合は==を使用してください。
効率的な順序付けの例:
steps: # ... receive steps ... # ... probabilistic sampler steps ... filter/Logs: description: Apply drop rules and data processing for logs output: - transform/Logs config: error_mode: ignore rules: - name: drop the log records description: drop all records which has severity text INFO conditions: - log.severity_text == "INFO" context: log filter/Metrics: description: Apply drop rules and data processing for metrics output: - transform/Metrics config: error_mode: ignore rules: - name: drop-internal-metrics description: drop internal metric conditions: - IsMatch(name, "^internal\\.") context: metric - name: drop-debug-datapoints description: drop-debug-datapoints conditions: - attributes["metric.type"] == "debug" context: datapoint filter/Traces: description: Apply drop rules and data processing for traces output: - transform/Traces config: error_mode: ignore rules: - name: drop-health-endpoint description: drop-health-endpoint conditions: - attributes["http.path"] == "/health" context: span - name: drop-debug-events description: drop-debug-events conditions: - name == 'debug_event' context: span_event # ... transformer steps...OTTLブール式リファレンス
完全な OTTL 構文と追加の演算子については、以下を参照してください。
次のステップ
- フィルタリング前にデータを変更するための変換プロセッサについて学習します
- 確率的ボリューム削減についてはサンプリングプロセッサを参照してください
- 完全な構文については、 YAML 設定リファレンスを参照してください。