Sha256: 66094ed26fd669224033402055a890d0a92aedba11ccb00a4e99868324c80b51

Contents?: true

Size: 1.92 KB

Versions: 12

Compression:

Stored size: 1.92 KB

Contents

# typed: false

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

module Datadog
  module Tracing
    module Contrib
      module ActionCable
        module Events
          # Defines instrumentation for 'perform_action.action_cable' event.
          #
          # An action, triggered by a WebSockets client, invokes a method
          # in the server's channel instance.
          module PerformAction
            include ActionCable::RootContextEvent

            EVENT_NAME = 'perform_action.action_cable'.freeze

            module_function

            def event_name
              self::EVENT_NAME
            end

            def span_name
              Ext::SPAN_ACTION
            end

            def span_type
              # A request to perform_action comes from a WebSocket connection
              Tracing::Metadata::Ext::AppTypes::TYPE_WEB
            end

            def process(span, _event, _id, payload)
              channel_class = payload[:channel_class]
              action = payload[:action]

              span.service = configuration[:service_name] if configuration[:service_name]
              span.resource = "#{channel_class}##{action}"
              span.span_type = span_type

              # 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_CHANNEL_CLASS, channel_class)
              span.set_tag(Ext::TAG_ACTION, action)

              span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
              span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ACTION)
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.8.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.7.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.6.1 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.6.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.5.2 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.5.1 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.5.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.4.2 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.4.1 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.4.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb
ddtrace-1.3.0 lib/datadog/tracing/contrib/action_cable/events/perform_action.rb