Sha256: 5155491ca086661bda724554d870fe4bdfc4a80cee532e03012e7c818fc75804

Contents?: true

Size: 1.89 KB

Versions: 21

Compression:

Stored size: 1.89 KB

Contents

require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_record/ext'
require 'ddtrace/contrib/active_record/event'

module Datadog
  module Contrib
    module ActiveRecord
      module Events
        # Defines instrumentation for instantiation.active_record event
        module Instantiation
          include ActiveRecord::Event

          EVENT_NAME = 'instantiation.active_record'.freeze

          module_function

          def supported?
            Gem.loaded_specs['activerecord'] \
              && Gem.loaded_specs['activerecord'].version >= Gem::Version.new('4.2')
          end

          def event_name
            self::EVENT_NAME
          end

          def span_name
            Ext::SPAN_INSTANTIATION
          end

          def process(span, event, _id, payload)
            # Inherit service name from parent, if available.
            span.service = if configuration[:orm_service_name]
                             configuration[:orm_service_name]
                           elsif span.parent
                             span.parent.service
                           else
                             Ext::SERVICE_NAME
                           end

            span.resource = payload.fetch(:class_name)
            span.span_type = Ext::SPAN_TYPE_INSTANTIATION

            # 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)

            span.set_tag(Ext::TAG_INSTANTIATION_CLASS_NAME, payload.fetch(:class_name))
            span.set_tag(Ext::TAG_INSTANTIATION_RECORD_COUNT, payload.fetch(:record_count))
          rescue StandardError => e
            Datadog.logger.debug(e.message)
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.51.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.50.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.49.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.48.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.47.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.46.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.45.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.44.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.43.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.42.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.41.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ls-trace-0.2.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.40.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.39.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.38.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.37.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.36.0 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.35.2 lib/ddtrace/contrib/active_record/events/instantiation.rb
ddtrace-0.35.1 lib/ddtrace/contrib/active_record/events/instantiation.rb