class ZuoraConnect::Telegraf

def write(direction: 'Unknown', tags: {}, values: {})

def write(direction: 'Unknown', tags: {}, values: {})
  time = Benchmark.measure do |bench|
    # To avoid writing metrics from rspec tests
    if Rails.env.to_sym != :test
      app_instance = Thread.current[:appinstance].present? ? Thread.current[:appinstance].id : 0
      tags = { app_name: app_name, process_type: process_type, app_instance: app_instance, pod_name: pod_name}.merge(tags)
      if direction == :inbound
        self.write_udp(series: INBOUND_METRICS_NAME, tags: tags, values: values) if INBOUND_METRICS
      elsif direction == :outbound
        self.write_udp(series: OUTBOUND_METRICS_NAME, tags: tags, values: values) if OUTBOUND_METRICS
      else
        self.write_udp(series: direction, tags: tags, values: values)
      end
    end
  end
  if ZuoraConnect.configuration.telegraf_debug
    Rails.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
    Rails.logger.debug(self.format_metric_log('Telegraf', values.to_s))
    Rails.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
  end
end