https://github.com/repeatedly/fluent-plugin-record-modifier
Fluentd filter plugin for modifying each event record
https://github.com/repeatedly/fluent-plugin-record-modifier
Keywords from Contributors
cncf data-collector fluentd msgpack fluentd-plugin
Last synced: about 21 hours ago
JSON representation
Repository metadata
Fluentd filter plugin for modifying each event record
- Host: GitHub
- URL: https://github.com/repeatedly/fluent-plugin-record-modifier
- Owner: repeatedly
- Created: 2013-04-07T00:59:32.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2025-08-23T21:26:57.000Z (6 months ago)
- Last Synced: 2026-02-24T14:18:15.296Z (7 days ago)
- Language: Ruby
- Homepage:
- Size: 125 KB
- Stars: 120
- Watchers: 5
- Forks: 42
- Open Issues: 25
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
README.md
Filter plugin to modify event record for Fluentd
Adding arbitary field to event record without customizing existence plugin.
For example, generated event from in_tail doesn't contain "hostname" of running machine.
In this case, you can use record_modifier to add "hostname" field to event record.
Requirements
| fluent-plugin-record-modifier | fluentd | ruby |
|---|---|---|
| >= 2.0.0 | >= v1.0.0 | >= 2.1 |
| >= 1.0.0 | >= v0.14.0 | >= 2.1 |
| < 1.0.0 | >= v0.12.0 | >= 1.9 |
Installation
Use RubyGems:
fluent-gem install fluent-plugin-record-modifier --no-document
Configuration
Use record_modifier filter.
<filter pattern>
@type record_modifier
<record>
gen_host "#{Socket.gethostname}"
foo bar
</record>
</filter>
If following record is passed:
{"message":"hello world!"}
then you got new record like below:
{"message":"hello world!", "gen_host":"oreore-mac.local", "foo":"bar"}
You can also use record_transformer like ${xxx} placeholders and access tag, time, record and tag_parts values by Ruby code.
<filter pattern>
@type record_modifier
<record>
tag ${tag}
tag_extract ${tag_parts[0]}-${tag_parts[1]}-foo
formatted_time ${Time.at(time).to_s}
new_field foo:${record['key1'] + record['dict']['key']}
</record>
</filter>
record_modifier is faster than record_transformer. See this comment.
But unlike record_transformer, record_modifier doesn't support following features for now.
- tag_suffix and tag_prefix
- dynamic key placeholder
prepare_value
Prepare values for filtering. This ruby code is evaluated in configure phase and prepared values can be used in <record>. Here is an example:
<filter pattern>
@type record_modifier
prepare_value require 'foo'; @foo = Foo.new
<record>
key ${@foo.method1}
</record>
</filter>
This feature is useful for using external library.
char_encoding
Fluentd including some plugins treats logs as a BINARY by default to forward.
But a user sometimes wants to process logs depends on their requirements, e.g. handling char encoding correctly.
char_encoding parameter is useful for this case.
<filter pattern>
@type record_modifier
# set UTF-8 encoding information to string.
char_encoding utf-8
# change char encoding from 'UTF-8' to 'EUC-JP'
char_encoding utf-8:euc-jp
</filter>
In char_encoding from:to case, it replaces invalid character with safe character.
remove_keys
The logs include needless record keys in some cases.
You can remove it by using remove_keys parameter.
<filter pattern>
@type record_modifier
# remove key1 and key2 keys from record
remove_keys key1,key2
</filter>
If following record is passed:
{"key1":"hoge", "key2":"foo", "key3":"bar"}
then you got new record like below:
{"key3":"bar"}
Since v2.2.0, remove_keys supports nested key delete via record_accessor syntax.
whitelist_keys
If you want to handle the set of explicitly specified keys, you can use whitelist_keys of this plugin. It's exclusive with remove_keys.
<filter pattern>
@type record_modifier
# remove all keys except for key1 and key2
whitelist_keys key1,key2
</filter>
If following record is passed:
{"key1":"hoge", "key2":"foo", "key3":"bar"}
then you got new record like below:
{"key1":"hoge", "key2":"foo"}
replace_keys_value
If you want to replace specific value for keys you can use replace section.
<filter pattern>
@type record_modifier
# replace key key1
<replace>
# your key name
key key1
# your regexp
expression /^(?<start>.+).{2}(?<end>.+)$/
# replace string
replace \k<start>ors\k<end>
</replace>
# replace key key2
<replace>
# your key name
key key2
# your regexp
expression /^(.{1}).{2}(.{1})$/
# replace string
replace \1ors\2
</replace>
</filter>
If following record is passed:
{"key1":"hoge", "key2":"hoge", "key3":"bar"}
then you got new record like below:
{"key1":"horse", "key2":"horse", "key3":"bar"}
Ruby code trick for complex logic
If you need own complex logic in filter, writing filter plugin is better. But if you don't want to write new plugin, you can use temporal key trick like below:
<filter reform.**>
@type record_modifier
remove_keys _dummy_
<record>
_dummy_ ${if record.has_key?('foo'); record['bar'] = 'Hi!'; end; nil}
</record>
</filter>
record_modifier output
Output plugin version of record_modifier filter. If you want to process events and change tag at the same time, this plugin is useful.
<match pattern>
@type record_modifier
tag foo.${record["field1"]}
<record>
gen_host "#{Socket.gethostname}"
foo bar
</record>
</match>
Copyright
Owner metadata
- Name: Masahiro Nakagawa
- Login: repeatedly
- Email:
- Kind: user
- Description:
- Website: http://repeatedly.github.com/
- Location: Japan
- Twitter:
- Company: Arm Treasure Data, Inc.
- Icon url: https://avatars.githubusercontent.com/u/16928?v=4
- Repositories: 100
- Last ynced at: 2024-04-21T03:22:37.026Z
- Profile URL: https://github.com/repeatedly
GitHub Events
Total
- Pull request event: 3
- Fork event: 2
- Watch event: 3
- Issue comment event: 3
- Push event: 1
Last Year
- Pull request event: 1
- Fork event: 1
- Watch event: 1
- Issue comment event: 2
Committers metadata
Last synced: 2 days ago
Total Commits: 111
Total Committers: 17
Avg Commits per committer: 6.529
Development Distribution Score (DDS): 0.333
Commits in past year: 3
Committers in past year: 2
Avg Commits per committer in past year: 1.5
Development Distribution Score (DDS) in past year: 0.333
| Name | Commits | |
|---|---|---|
| Masahiro Nakagawa | r****y@g****m | 74 |
| Hiroshi Hatake | c****c@g****m | 11 |
| Ilia | i****n@g****m | 7 |
| Kentaro Hayashi | h****i@c****m | 2 |
| Satoshi Matsumoto | k****z@g****m | 2 |
| Scott Leggett | s****t@s****u | 2 |
| TAGOMORI Satoshi | t****s@g****m | 2 |
| mia-0032 | m****7@g****m | 2 |
| Satoshi Matsumoto | s****o@c****m | 1 |
| Frits Vlaanderen | f****s | 1 |
| M.Shibuya | m****a@g****m | 1 |
| Marijus Ravickas | m****s@g****m | 1 |
| Ori Hoch | o****i@u****m | 1 |
| Patrick Decat | p****t@g****m | 1 |
| RobertLeeuwis | 6****s | 1 |
| choplin | c****n@g****m | 1 |
| kiyoto | me@k****m | 1 |
Committer domains:
- ktamura.com: 1
- uumpa.com: 1
- cookpad.com: 1
- sl.id.au: 1
- clear-code.com: 1
Issue and Pull Request metadata
Last synced: 5 months ago
Total issues: 45
Total pull requests: 31
Average time to close issues: 8 months
Average time to close pull requests: 3 months
Total issue authors: 41
Total pull request authors: 19
Average comments per issue: 1.69
Average comments per pull request: 0.97
Merged pull request: 27
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 3
Past year average time to close issues: N/A
Past year average time to close pull requests: about 9 hours
Past year issue authors: 0
Past year pull request authors: 2
Past year average comments per issue: 0
Past year average comments per pull request: 0.33
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- zffocussss (2)
- mindw (2)
- dannyk81 (2)
- dasterintempus (2)
- shaburov (1)
- StevenACoffman (1)
- vimalk78 (1)
- bimalvasan (1)
- ghost (1)
- lukasbar (1)
- estuart (1)
- ckazimie (1)
- TimofeyGudilin-TomTom (1)
- iwilltry42 (1)
- rverma-jm (1)
Top Pull Request Authors
- repeatedly (8)
- cosmo0920 (3)
- kaorimatz (2)
- tagomoris (2)
- kenhys (2)
- RobertLeeuwis (1)
- choplin (1)
- kiyoto (1)
- ferbar (1)
- marijus-ravickas (1)
- alexfouche (1)
- smallcreep (1)
- smlx (1)
- mia-0032 (1)
- frits-v (1)
Top Issue Labels
Top Pull Request Labels
- enhancement (1)
Package metadata
- Total packages: 2
-
Total downloads:
- rubygems: 190,739,102 total
- Total docker downloads: 1,962,264,048
- Total dependent packages: 0 (may contain duplicates)
- Total dependent repositories: 210 (may contain duplicates)
- Total versions: 46
- Total maintainers: 6
gem.coop: fluent-plugin-record-modifier
Filter plugin for modifying event record
- Homepage: https://github.com/repeatedly/fluent-plugin-record-modifier
- Documentation: http://www.rubydoc.info/gems/fluent-plugin-record-modifier/
- Licenses: MIT
- Latest release: 2.2.1 (published 6 months ago)
- Last Synced: 2026-03-02T06:02:21.995Z (1 day ago)
- Versions: 23
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 95,400,047 Total
- Docker Downloads: 981,132,024
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Docker downloads count: 0.09%
- Average: 0.093%
- Downloads: 0.283%
- Maintainers (6)
rubygems.org: fluent-plugin-record-modifier
Filter plugin for modifying event record
- Homepage: https://github.com/repeatedly/fluent-plugin-record-modifier
- Documentation: http://www.rubydoc.info/gems/fluent-plugin-record-modifier/
- Licenses: MIT
- Latest release: 2.2.1 (published 6 months ago)
- Last Synced: 2026-02-28T12:02:51.976Z (3 days ago)
- Versions: 23
- Dependent Packages: 0
- Dependent Repositories: 210
- Downloads: 95,339,055 Total
- Docker Downloads: 981,132,024
-
Rankings:
- Docker downloads count: 0.124%
- Downloads: 0.348%
- Dependent repos count: 2.11%
- Forks count: 4.188%
- Average: 4.589%
- Stargazers count: 5.073%
- Dependent packages count: 15.693%
- Maintainers (6)
Dependencies
- rake >= 0.9.2 development
- test-unit ~> 3.3 development
- fluentd >= 1.0, < 2
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
Score: 29.300076825965643