Sha256: 5ed9f83da274557b6c173663a0a807b293a72fdfac325b5d0884f7dedb723263

Contents?: true

Size: 1.59 KB

Versions: 32

Compression:

Stored size: 1.59 KB

Contents

if defined?(::Sidekiq)
  Appsignal.logger.info('Loading Sidekiq integration')

  module Appsignal
    module Integrations
      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
    end
  end

  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      chain.add Appsignal::Integrations::SidekiqPlugin
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
appsignal-0.12.beta.40 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.39 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.38 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.37 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.36 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.35 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.34 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.33 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.32 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.15 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.14 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.14.beta.1 lib/appsignal/integrations/sidekiq.rb