Sha256: 92e4053eab3d3bafbeb9a81cdb15361c336a3fa86437005f764b8a481fb9b768

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/action_cable/event'

module Datadog
  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
            Datadog::Ext::AppTypes::WEB
          end

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

            span.service = 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

            span.set_tag(Ext::TAG_CHANNEL_CLASS, channel_class)
            span.set_tag(Ext::TAG_ACTION, action)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.33.1 lib/ddtrace/contrib/action_cable/events/perform_action.rb
ddtrace-0.33.0 lib/ddtrace/contrib/action_cable/events/perform_action.rb
ddtrace-0.32.0 lib/ddtrace/contrib/action_cable/events/perform_action.rb
ddtrace-0.31.1 lib/ddtrace/contrib/action_cable/events/perform_action.rb
ddtrace-0.31.0 lib/ddtrace/contrib/action_cable/events/perform_action.rb