Sha256: 7e52e87059c166cf7041048591734c31b73d95997da2faae8c1a75350c8ce2ed

Contents?: true

Size: 998 Bytes

Versions: 48

Compression:

Stored size: 998 Bytes

Contents

require 'honeybadger'

module Honeybadger
  module Rack
    class MetricsReporter
      GC_TIME_METRIC = 'app.gc.time'.freeze
      GC_COLLECTIONS_METRIC = 'app.gc.collections'.freeze

      def initialize(app, config)
        @app = app
        @config = config
      end

      def call(env)
        start = Time.now
        track_gc? and GC::Profiler.clear
        status, headers, body = app.call(env)
        duration = (Time.now - start) * 1000
        report_metrics(status, duration)
        [status, headers, body]
      end

      private

      attr_reader :app, :config

      def track_gc?
        config[:'metrics.gc_profiler']
      end

      def report_metrics(status, duration)
        Agent.timing("app.request.#{status}", duration)

        if track_gc? && GC::Profiler.total_time > 0
          Agent.timing(GC_TIME_METRIC, GC::Profiler.total_time * 1000)
          Agent.increment(GC_COLLECTIONS_METRIC, GC::Profiler.result[/\d+/].to_i)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
honeybadger-2.6.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.6.0 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.5.3 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.5.2 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.5.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.5.0 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.4.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.4.0 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.3.3 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.3.2 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.3.2.beta.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.3.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.3.0 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.2.0 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.2.0.beta.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.1.6.beta.1 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.1.5 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.1.4 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.1.3 lib/honeybadger/rack/metrics_reporter.rb
honeybadger-2.1.1 lib/honeybadger/rack/metrics_reporter.rb