0

I am trying to mask password using @type record_transformer some of my application log statement don't have message due to this am getting below Error from td-agent log file is there any to over come this issue. How to ignore this if message field not found.

2021-09-28 18:05:15.751529402 +0000 fluent.warn: {"error":"#<RuntimeError: failed to expand `record[\"message\"].gsub(/[Pp]assword*([^,]*)/,'******').gsub(/([Aa]uthorization\\s*.\\s*[Bb]earer\\s)[\\w\\.\\-^]+/,'******').gsub(/([Aa]uthorization_ml\\s*.\\s*[Bb]earer\\s)[\\w\\.\\-^]+/,'******')` : error = undefined method `gsub' for nil:NilClass>","location":"/opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.11.1/lib/fluent/plugin/filter_record_transformer.rb:310:in `rescue in expand'","
Aswath Murugan
  • 505
  • 2
  • 4
  • 12

1 Answers1

1

The object which is having #gsub called (likely a String) is nil. Look for missing data getting to the record_transformer - maybe an incorrect Hash lookup returning nil?

You can guard on nil with the #nil? method on each object.

if obj.nil?
  # do thing
end
Sivver
  • 34
  • 4
  • Thanks, is there any example configuration? Filter config @type record_transformer enable_ruby message ${record["message"].gsub(/[Pp]assword*([^,]*)/,'******').gsub(/([Aa]uthorization\s*.\s*[Bb]earer\s)[\w\.\-^]+/,'******').gsub(/([Aa]uthorization_ml\s*.\s*[Bb]earer\s)[\w\.\-^]+/,'******')} – Aswath Murugan Sep 29 '21 at 04:43