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.11.18 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.rc.7 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.rc.6 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.rc.5 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.54 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.53 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.52 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.51 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.17 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.50 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.49 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.16 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.48 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.47 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.46 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.45 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.44 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.43 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.42 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.41 lib/appsignal/integrations/sidekiq.rb