Sha256: 84bd3c8206cf84c2d8c43cdcf7df8ff3b126f3a03a04f4c4a8945794b3e7c362

Contents?: true

Size: 897 Bytes

Versions: 7

Compression:

Stored size: 897 Bytes

Contents

module SemanticLogger
  module Metrics
    class NewRelic < Subscriber
      attr_accessor :prefix

      # Parameters:
      #   :prefix [String]
      #     Prefix to add to every metric before forwarding to NewRelic
      #     Default: 'Custom'
      def initialize(options = {})
        options = options.dup
        @prefix = options.delete(:prefix) || 'Custom'
        raise(ArgumentError, "Unknown options: #{options.inspect}") if options.size > 0
      end

      def call(log)
        metric = log.metric
        # Add prefix for NewRelic
        metric = "#{prefix}/#{metric}" unless metric.start_with?(prefix)

        if duration = log.duration
          # Convert duration to seconds
          ::NewRelic::Agent.record_metric(metric, duration / 1000.0)
        else
          ::NewRelic::Agent.increment_metric(metric, log.metric_amount || 1)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
semantic_logger-4.1.1 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-4.1.0 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-4.0.0 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-4.0.0.rc1 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-4.0.0.beta2 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-4.0.0.beta1 lib/semantic_logger/metrics/new_relic.rb
semantic_logger-3.3.0 lib/semantic_logger/metrics/new_relic.rb