【datadog】datadog Logs ~ 基本編 ~

◾️はじめに

https://dk521123.hatenablog.com/entry/2025/02/14/200308

の続き。

今回は、パースやリマッパーに関して、深掘りする。

目次

【1】Define parsing rules
 1)構文
 2)パース規則
 3)日時のパース
 4)サンプル
【2】Remapper
 1)Log status remapper
【3】Processor
 1)カテゴリープロセッサー
 2)Array processor / 配列プロセッサー

【1】Define parsing rules

* 公式ドキュメントも参照

https://docs.datadoghq.com/ja/logs/log_configuration/parsing/

1)構文

「john connected on 11/08/2017」の場合

[パース規則名(e.g. MyParsingRule)] [パース規則 (後述「3)パース規則」参照)]
MyParsingRule %{word:user} connected on %{date("MM/dd/yyyy"):date}

Tips:ルールは複数指定可能

MyParsingRule1 %{word:user} connected on %{date("MM/dd/yyyy"):date}
MyParsingRule2 ...

2)パース規則

https://docs.datadoghq.com/ja/logs/log_configuration/parsing/

%{MATCHER:EXTRACT:FILTER} 構文を使用して記述
名称 説明
Matcher 期待する内容 (数値、単語、スペース以外など) を記述する規則
Extract (任意) Matcher と一致するテキストをキャプチャする対象を表す識別子
Filter (任意) 一致したテキストを変換するためのポストプロセッサー

Matcher

Matcher Explanations Memo
regex("pattern") 正規表現に一致 -
notSpace 次のスペースまでの文字列に一致 -
numberStr 10 進浮動小数点数に一致し、それを文字列としてパース -
word 単語境界で始まり、a-z、A-Z、0-9 の文字と _ (アンダースコア) 文字を含み、単語境界で終わる単語にマッチ 文字列じゃないことに注意
data スペースと改行を含め、任意の文字列に一致。正規表現の .* と同じ -

Filter

Filter Explanations Memo
number 一致部分を倍精度数としてパース

3)日時のパース

https://docs.datadoghq.com/logs/log_configuration/parsing/?tab=matchers#parsing-dates

Example Define parsing rules
2007-08-31T19:22:22 %{date("yyyy-MM-dd'T'HH:mm:ss"):demo_datetime}

4)サンプル

# 典型的な非構造化ログの例 Define parsing rules
ex1 john connected on 11/08/2017 MyParsingRule %{word:user} connected on %{date("MM/dd/yyyy"):date}
ex2 2020-10-19 09:45:12.430 WARN DEV GET /api/accounts/me - 8f738764-db38-49fe-a28f-412edc0ee8a6 qtp1886478937-17 Unauthorized access to path. path=[/api/accounts/me] method=[GET] example_chat_dev %{date("yyyy-MM-dd hh:mm:ss.SSS"):date} %{word:logLevel} %{word:runtimeLoggerName} %{word:http.method} %{notSpace:http.url_details.path} %{notSpace:userId} %{notSpace:sessionId} %{notSpace:threadName} %{data:message}
ex3 john_1a2b3c4 connected on 11/08/2017 MyParsingRule %{regex("[a-z]"):user.firstname}_%{regex("[a-zA-Z0-9]"):user.id} .*

https://docs.datadoghq.com/logs/log_configuration/parsing/?tab=matchers#regex

【2】Remapper

* 任意のソース属性やタグを、別のターゲット属性やタグにマッピングし直すプロセッサー

https://docs.datadoghq.com/ja/service_management/events/pipelines_and_processors/remapper/

手順例

(1) Select the processor type
 => Remapper
(2) Name the processor
 => 任意の文字列(e.g. hello world mapper)
(3) Set attribute(s) or tag key to remap(リマップのための属性またはタグキーの設定)
 => タグの場合、[Attribute(s)]->[Tag]に変更
(4) Set target attribute(s) or tag key (対象属性またはタグキーの設定)
 => タグの場合、[Attribute(s)]->[Tag]に変更

1)Log status remapper

* Status を変更することができるマッパー

https://docs.datadoghq.com/logs/log_configuration/processors/?tab=ui#log-status-remapper

* カテゴリープロセッサー(後述【3】の「1)カテゴリープロセッサー」を参照)
 と組み合わせると、Statusを変更することができる(e.g. INFO=>WARNに変更)
 => 以下のサイトを参照

公式ドキュメント
https://docs.datadoghq.com/ja/logs/guide/remap-custom-severity-to-official-log-status/
一般サイト
https://blog.vtryo.me/entry/datadog-log-parse-and-remap
https://qiita.com/smallpalace/items/144da16c2c8cda61f3a4

【3】Processor

1)カテゴリープロセッサー

* カスタム値と期待される値の間のマッピングを定義する
 => 指定された検索クエリに一致するイベントに、新しい属性を追加するために使用

https://docs.datadoghq.com/ja/service_management/events/pipelines_and_processors/category_processor/

2)Array processor / 配列プロセッサー

* 配列要素に対して、「Select the array processor」で
 以下の3つの操作を行うことができるプロセッサー

[1] Select value from a matching element
[2] Compute the length of an array
[3] Append a value to an array

https://docs.datadoghq.com/logs/log_configuration/processors/?tab=ui#array-processor

* 詳細は、以下の関連記事を参照のこと

datadog Logs ~ Array processor / 配列プロセッサー
https://dk521123.hatenablog.com/entry/2025/06/08/011248

関連記事

datadog ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2024/03/30/004746
datadog ~ 属性/ファセット/属性検索@ ~
https://dk521123.hatenablog.com/entry/2025/02/26/150349
datadog ~ タグ ~
https://dk521123.hatenablog.com/entry/2025/02/27/002502
datadog pipeline ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2025/04/14/145556
datadog pipeline ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/06/04/221715
datadog dashboard ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/02/09/000106
datadog Logs ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/02/14/200308
datadog Logs ~ Array processor / 配列プロセッサー
https://dk521123.hatenablog.com/entry/2025/06/08/011248
datadog Alert ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/02/16/232413