Sha256: 76afee252ecb217abbc371e92f6c799680496bedb5fe396a2c4e6578edde38e6

Contents?: true

Size: 1.78 KB

Versions: 24

Compression:

Stored size: 1.78 KB

Contents

require_relative '../../../metadata/ext'
require_relative '../../analytics'
require_relative '../ext'
require_relative '../event'

module Datadog
  module Tracing
    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)
              span.resource = payload.fetch(:class_name)
              span.span_type = Ext::SPAN_TYPE_INSTANTIATION
              span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
              span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_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
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.23.2 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.23.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.22.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.21.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.21.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.20.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.19.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.18.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.17.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.16.2 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.16.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.16.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.15.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.14.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.13.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.13.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.12.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.12.0 lib/datadog/tracing/contrib/active_record/events/instantiation.rb
ddtrace-1.11.1 lib/datadog/tracing/contrib/active_record/events/instantiation.rb