Using dynamic value in google_pubsub filter plugin attributes field

Hi all,

I don't know how to give a dynamic value to this attributes field in google_pubsub output plugin.

Currently this is what I do, which is not DRY

output {
  if [name] == "userRegistered" {
    google_pubsub {
      project_id => "a"
      topic => "ab"
      json_key_file => "abc"
      attributes => {
        "eventName" => "userRegistered"
      }
    }
  }
}

This one tho, won't work, even tho the conditional statement can read from the name field

output {
  if [name] == "userRegistered" {
    google_pubsub {
      project_id => "a"
      topic => "ab"
      json_key_file => "abc"
      attributes => {
        "eventNameA" => "%{[name]}"
        "eventNameB" => "%{name}"
        "eventNameC" => "[name]"
      }
    }
  }
}

What am I missing here?

The output does not sprintf the attributes, so you cannot use a sprintf reference.

So there's no way to make it dynamic?

With the existing plugin I do not think it can be done. You could change this line from

attributes.each { |k, v| builder.putAttributes(k, v) }

to

attributes.each { |k, v| builder.putAttributes(k, event.sprintf(v)) }

and rebuild the plugin from source. Or submit a PR that does that, or open an issue on github requesting that someone else do so :slight_smile:

If doing either of the latter then you might want to consider whether anyone on the planet would consider it useful to sprintf both k and v!

attributes.each { |k, v| builder.putAttributes(event.sprintf(k), event.sprintf(v)) }
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.