lib/semantic_logger/formatters/signalfx.rb in semantic_logger-4.6.1 vs lib/semantic_logger/formatters/signalfx.rb in semantic_logger-4.7.0

- old
+ new

@@ -1,15 +1,15 @@ -require 'json' +require "json" module SemanticLogger module Formatters class Signalfx < Base - attr_accessor :token, :dimensions, :hash, :log, :logger, :gauge_name, :counter_name + attr_accessor :token, :dimensions, :hash, :gauge_name, :counter_name def initialize(token:, dimensions: nil, - gauge_name: 'Application.average', - counter_name: 'Application.counter', + gauge_name: "Application.average", + counter_name: "Application.counter", time_format: :ms, **args) @token = token @dimensions = dimensions.map(&:to_sym) if dimensions @@ -21,23 +21,23 @@ # Create SignalFx friendly metric. # Strip leading '/' # Convert remaining '/' to '.' def metric - name = log.metric.to_s.sub(/\A\/+/, '') + name = log.metric.to_s.sub(%r{\A/+}, "") if log.dimensions - name.tr!('/', '.') + name.tr!("/", ".") hash[:metric] = name else # Extract class and action from metric name - names = name.split('/') + names = name.split("/") h = (hash[:dimensions] ||= {}) if names.size > 1 h[:action] = names.pop - h[:class] = names.join('::') + h[:class] = names.join("::") else - h[:class] = 'Unknown' + h[:class] = "Unknown" h[:action] = names.first || log.metric end hash[:metric] = log.duration ? gauge_name : counter_name end @@ -65,9 +65,10 @@ else log.named_tags.each_pair do |name, value| name = name.to_sym value = value.to_s next if value.empty? + h[name] = value if dimensions&.include?(name) end end h[:host] = logger.host if log_host && logger.host h[:application] = logger.application if log_application && logger.application