Sha256: ec6fdb7a89da5d2ee92e65ad8f12b96656409d2cb16bf182eae42c2524320e1b

Contents?: true

Size: 1.33 KB

Versions: 27

Compression:

Stored size: 1.33 KB

Contents

module Datadog
  module Contrib
    module SuckerPunch
      SERVICE = 'sucker_punch'.freeze
      COMPATIBLE_WITH = Gem::Version.new('2.0.0')

      # Responsible for hooking the instrumentation into `sucker_punch`
      module Patcher
        include Base
        register_as :sucker_punch, auto_patch: true
        option :service_name, default: SERVICE

        @patched = false

        module_function

        def patch
          return @patched if patched? || !compatible?

          require 'ddtrace/ext/app_types'
          require_relative 'exception_handler'
          require_relative 'instrumentation'

          add_pin!
          ExceptionHandler.patch!
          Instrumentation.patch!

          @patched = true
        rescue => e
          Datadog::Tracer.log.error("Unable to apply SuckerPunch integration: #{e}")
          @patched
        end

        def patched?
          @patched
        end

        def compatible?
          return unless defined?(::SuckerPunch::VERSION)

          Gem::Version.new(::SuckerPunch::VERSION) >= COMPATIBLE_WITH
        end

        def add_pin!
          Pin.new(get_option(:service_name), app: 'sucker_punch', app_type: Ext::AppTypes::WORKER).tap do |pin|
            pin.onto(::SuckerPunch)
          end
        end

        private_class_method :compatible?, :add_pin!
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ddtrace-0.16.1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.15.0.internaltracinfeature1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.16.0 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.2.disableprotocolversion4 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.15.0 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.2.withoutpriorityparsing1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.2 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.15.0.beta1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.0 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.0.rc1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.13.2 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.0.beta2 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.14.0.beta1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.13.1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.13.0 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.12.1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.13.0.beta1 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.12.0 lib/ddtrace/contrib/sucker_punch/patcher.rb
ddtrace-0.12.0.rc1 lib/ddtrace/contrib/sucker_punch/patcher.rb