Sha256: 2297f6cd5297cd391432b633d804deb61b4b0bf9175f25446b201d4b0567eb30

Contents?: true

Size: 981 Bytes

Versions: 31

Compression:

Stored size: 981 Bytes

Contents

require 'active_support/core_ext/module/aliasing'
require 'roqua/support/log_wrapper'

module Roqua
  module Support
    module Instrumentation
      def with_instrumentation(message, options = {})
        started_at = Time.now.to_f
        Roqua.logger.info("#{message}:started", options)
        value = yield
        finished_at = Time.now.to_f
        duration = finished_at - started_at
        Roqua.logger.info("#{message}:finished", {duration: duration}.merge(options))
        Roqua.stats.submit("#{message}.finished", 1)
        Roqua.stats.submit("#{message}.duration", duration)
        value
      rescue => e
        Roqua.logger.error("#{message}:failed", {exception: e.class.name, message: e.message}.merge(options))
        Roqua.stats.submit("#{message}.failed", 1)
        raise
      end

      def eventlog
        Roqua.logger
      end
    end
  end

  # Roqua::Logging is deprecated, this will keep it alive for now
  Logging = Support::Instrumentation
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
roqua-support-0.4.6 lib/roqua/support/instrumentation.rb
roqua-support-0.4.5 lib/roqua/support/instrumentation.rb
roqua-support-0.4.4 lib/roqua/support/instrumentation.rb
roqua-support-0.4.3 lib/roqua/support/instrumentation.rb
roqua-support-0.4.2 lib/roqua/support/instrumentation.rb
roqua-support-0.4.1 lib/roqua/support/instrumentation.rb
roqua-support-0.4.0 lib/roqua/support/instrumentation.rb
roqua-support-0.3.5 lib/roqua/support/instrumentation.rb
roqua-support-0.3.4 lib/roqua/support/instrumentation.rb
roqua-support-0.3.3 lib/roqua/support/instrumentation.rb
roqua-support-0.3.2 lib/roqua/support/instrumentation.rb
roqua-support-0.3.1 lib/roqua/support/instrumentation.rb
roqua-support-0.3.0 lib/roqua/support/instrumentation.rb
roqua-support-0.1.34 lib/roqua/support/instrumentation.rb
roqua-support-0.1.33 lib/roqua/support/instrumentation.rb
roqua-support-0.1.32 lib/roqua/support/instrumentation.rb
roqua-support-0.1.31 lib/roqua/support/instrumentation.rb
roqua-support-0.1.30 lib/roqua/support/instrumentation.rb
roqua-support-0.1.29 lib/roqua/support/instrumentation.rb
roqua-support-0.1.28 lib/roqua/support/instrumentation.rb