Sha256: 2cd1620b23478de0aacf856809ff4e3691a18e71f5ca00256d8e1ee76235786d

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_support/notifications/event'
require 'ddtrace/contrib/kafka/ext'

module Datadog
  module Contrib
    module Kafka
      # Defines basic behaviors for an ActiveSupport event.
      module Event
        def self.included(base)
          base.include(ActiveSupport::Notifications::Event)
          base.extend(ClassMethods)
        end

        # Class methods for Kafka events.
        module ClassMethods
          def event_name
            self::EVENT_NAME
          end

          def span_options
            { service: configuration[:service_name] }
          end

          def tracer
            -> { configuration[:tracer] }
          end

          def configuration
            Datadog.configuration[:kafka]
          end

          def process(span, _event, _id, payload)
            span.service = configuration[:service_name]
            span.set_tag(Ext::TAG_CLIENT, payload[:client_id])

            # Set analytics sample rate
            if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
              Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
            end

            # Measure service stats
            Contrib::Analytics.set_measured(span)

            report_if_exception(span, payload)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/contrib/kafka/event.rb
ddtrace-0.51.0 lib/ddtrace/contrib/kafka/event.rb
ddtrace-0.50.0 lib/ddtrace/contrib/kafka/event.rb