lib/fluent/plugin/out_mixpanel.rb in fluent-plugin-mixpanel-0.0.3 vs lib/fluent/plugin/out_mixpanel.rb in fluent-plugin-mixpanel-0.0.4

- old
+ new

@@ -1,13 +1,16 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput Fluent::Plugin.register_output('mixpanel', self) config_param :project_token, :string config_param :distinct_id_key, :string - config_param :event_key, :string + config_param :event_key, :string, :default => nil config_param :ip_key, :string, :default => nil + config_param :remove_tag_prefix, :string, :default => nil + config_param :event_map_tag, :bool, :default => false + def initialize super require 'mixpanel-ruby' end @@ -15,22 +18,16 @@ super @project_tokey = conf['project_token'] @distinct_id_key = conf['distinct_id_key'] @event_key = conf['event_key'] @ip_key = conf['ip_key'] + @remove_tag_prefix = conf['remove_tag_prefix'] + @event_map_tag = conf['event_map_tag'] - if @project_token.empty? - raise Fluent::ConfigError, "'project_token' must be specifed." + if @event_key.nil? and !@event_map_tag + raise Fluent::ConfigError, "'event_key' must be specifed when event_map_tag == false." end - - if @distinct_id_key.empty? - raise Fluent::ConfigError, "'distinct_id_key' must be specifed." - end - - if @event_key.empty? - raise Fluent::ConfigError, "'event_key' must be specifed." - end end def start super @tracker = Mixpanel::Tracker.new(@project_token) @@ -55,10 +52,12 @@ else log.warn('no distinct_id') return end - if record[@event_key] + if @event_map_tag + data['event'] = tag.gsub(/^#{@remove_tag_prefix}(\.)?/, '') + elsif record[@event_key] data['event'] = record[@event_key] record.delete(@event_key) else log.warn('no event') return