Sha256: f9b04d978c72d3126076c6d29a136c6e0eeb564edf1d2b018a050ba31622e942

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

# typed: ignore

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/graft/hook'
require 'sqreen/ecosystem_integration/around_callbacks'

module Sqreen
  class EcosystemIntegration
    module InstrumentationService
      class << self
        # @param [String] module_name
        # @param [String] method in form A::B#c or A::B.c
        # @param [Hash{Symbol=>Proc}] spec
        def instrument(module_name, method, spec)
          hook = Sqreen::Graft::Hook[method].add do
            if spec[:before]
              cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'pre', spec[:before])
              before(nil, flow: true, &cb)
            end

            if spec[:after]
              cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'post', spec[:after])
              after(nil, flow: true, &cb)
            end

            if spec[:raised]
              cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'failing', spec[:raised])
              raised(nil, flow: true, &cb)
            end

            if spec[:ensured]
              cb = AroundCallbacks.wrap_instrumentation_hook(module_name, 'finally', spec[:ensured])
              ensured(nil, flow: true, &cb)
            end
          end
          hook.install
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sqreen-1.25.1 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.25.0 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.24.3 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.24.2 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.24.1 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.24.0 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.23.2 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.23.1 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.23.0 lib/sqreen/ecosystem_integration/instrumentation_service.rb
sqreen-1.22.1 lib/sqreen/ecosystem_integration/instrumentation_service.rb