Sha256: d0c3f172458ed8365e4e98f06506a9093d3caf383745c52c9e671f50953f4191

Contents?: true

Size: 1.57 KB

Versions: 46

Compression:

Stored size: 1.57 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['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 > 100 ? "#{text[0...97]}..." : 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

46 entries across 46 versions & 1 rubygems

Version Path
appsignal-0.12.beta.31 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.30 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.29 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.28 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.27 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.26 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.25 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.24 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.23 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.22 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.21 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.20 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.19 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.18 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.17 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.16 lib/appsignal/integrations/sidekiq.rb
appsignal-0.12.beta.15 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.13.beta.4 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.13.beta.3 lib/appsignal/integrations/sidekiq.rb
appsignal-0.11.13.beta.2 lib/appsignal/integrations/sidekiq.rb