Sha256: db67718c434a01ea0f345f7f01bacfb74fbaa5a81cfe7c7ed2ffdb69676757b0

Contents?: true

Size: 1.62 KB

Versions: 26

Compression:

Stored size: 1.62 KB

Contents

module Appsignal
  class Hooks
    class SidekiqPlugin
      def job_keys
        @job_keys ||= Set.new(%w(
            class args retried_at failed_at
            error_message error_class backtrace
            error_backtrace enqueued_at retry
        ))
      end

      def call(worker, item, queue)
        Appsignal.monitor_transaction(
          'perform_job.sidekiq',
          :class       => item['wrapped'] || item['class'],
          :method      => 'perform',
          :metadata    => formatted_metadata(item),
          :params      => format_args(item['args']),
          :queue_start => item['enqueued_at']
        ) do
          yield
        end
      end

      def formatted_metadata(item)
        {}.tap do |hsh|
          item.each do |key, val|
            hsh[key] = truncate(string_or_inspect(val)) unless job_keys.include?(key)
          end
        end
      end

      def string_or_inspect(string_or_other)
        if string_or_other.is_a?(String)
          string_or_other
        else
          string_or_other.inspect
        end
      end

      def format_args(args)
        args.map do |arg|
          truncate(string_or_inspect(arg))
        end
      end

      def truncate(text)
        text.size > 200 ? "#{text[0...197]}..." : text
      end
    end

    class SidekiqHook < Appsignal::Hooks::Hook
      register :sidekiq

      def dependencies_present?
        defined?(::Sidekiq)
      end

      def install
        ::Sidekiq.configure_server do |config|
          config.server_middleware do |chain|
            chain.add Appsignal::Hooks::SidekiqPlugin
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
appsignal-1.0.7 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.6 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.6.beta.4 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.6.beta.3 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.6.beta.2 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.6.beta.1 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.5 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.5.beta.4 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.5.beta.3 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.5.beta.2 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.5.beta.1 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.4 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.3 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.3.beta.2 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.3.beta.1 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.2 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.2.beta.4 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.2.beta.3 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.2.beta.2 lib/appsignal/hooks/sidekiq.rb
appsignal-1.0.2.beta.1 lib/appsignal/hooks/sidekiq.rb