0

I have a source event stream which is coming from a log tail. I'm trying to enrich this by using the filter directive. Some searching mentioned using #{ENV['MYVAR']} would work but I am getting an empty string as the value. The filter is as below:

<filter logtag.mytag>
  @type record_transformer
  enable_ruby
  <record>
    mykey "#{ENV['MYVAR']}"
  </record>
</filter>

Is it possible to add an env variable the way I'm doing it, and if so what am I doing incorrectly? Any help is appreciated.

Raghuveer
  • 1,737
  • 20
  • 27
  • 1
    Your syntax looks correct except that you did not mention true or false for `enable_ruby`. Ex - `enable_ruby true`. what is your input looks like and what are expecting after transformer?. – Imran Sep 30 '19 at 23:44
  • Thanks for replying. I found the mistake, I didn't mention that I was using a mac environment and had to set the env variables differently from linux. Updated more in my answer. – Raghuveer Oct 01 '19 at 05:11

1 Answers1

0

Along with what Imran mentioned (set enable_ruby to true), the mistake was that I was using a mac environment and it turns out we have to set the environment variable through launchctl to make it work instead of exporting it in bash profile or /etc/environment like we do in linux.

Command:

sudo launchctl setenv MYVAR varvalue

After doing that, it worked right away.

Raghuveer
  • 1,737
  • 20
  • 27