Sha256: 4d96f2a220b26c2ffa51cee73bd050d7c299b2709fa4da624ed1658a06d642b5

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

require 'ddtrace/contrib/active_support/notifications/subscriber'

module Datadog
  module Contrib
    module ActiveSupport
      module Notifications
        # Defines behaviors for an ActiveSupport::Notifications event.
        # Compose this into a module or class, then define
        # #event_name, #span_name, and #process. You can then
        # invoke Event.subscribe! to more easily subscribe to an event.
        module Event
          def self.included(base)
            base.send(:include, Subscriber)
            base.send(:extend, ClassMethods)
            base.send(:on_subscribe) { base.subscribe }
          end

          # Redefines some class behaviors for a Subscriber to make
          # it a bit simpler for an Event.
          module ClassMethods
            DEFAULT_TRACER = -> { Datadog.tracer }

            def subscribe!
              super
            end

            def subscription(span_name = nil, options = nil, tracer = nil)
              super(
                span_name || self.span_name,
                options || span_options,
                tracer || self.tracer,
                &method(:process)
              )
            end

            def subscribe(pattern = nil, span_name = nil, options = nil, tracer = nil)
              if supported?
                super(
                  pattern || event_name,
                  span_name || self.span_name,
                  options || span_options,
                  tracer || self.tracer,
                  &method(:process)
                )
              end
            end

            def supported?
              true
            end

            def span_options
              {}
            end

            def tracer
              DEFAULT_TRACER
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ddtrace-0.42.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ddtrace-0.41.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ls-trace-0.2.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ddtrace-0.40.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ddtrace-0.39.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ddtrace-0.38.0 lib/ddtrace/contrib/active_support/notifications/event.rb
ddtrace-0.37.0 lib/ddtrace/contrib/active_support/notifications/event.rb