Sha256: 26dbc1e06241bc8d2949ed1ac2149c243f2fd82e95b3c2d5c0a3b1ec6d9a653e

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'appsignal'

module Pallets
  module Middleware
    class AppsignalInstrumenter
      extend Appsignal::Hooks::Helpers

      def self.call(worker, job, context)
        job_status = nil
        transaction = Appsignal::Transaction.create(
          SecureRandom.uuid,
          Appsignal::Transaction::BACKGROUND_JOB,
          Appsignal::Transaction::GenericRequest.new(queue_start: job['created_at'])
        )

        Appsignal.instrument('perform_job.pallets') do
          begin
            yield
          rescue Exception => ex
            job_status = :failed
            transaction.set_error(ex)
            raise
          ensure
            transaction.set_action_if_nil("#{job['task_class']}#run (#{job['workflow_class']})")
            transaction.params = filtered_context(context)
            formatted_metadata(job).each { |kv| transaction.set_metadata(*kv) }
            transaction.set_http_or_background_queue_start
            Appsignal.increment_counter('pallets_job_count', 1, status: job_status || :successful)
          end
        end
      ensure
        Appsignal::Transaction.complete_current!
      end

      def self.filtered_context(context)
        Appsignal::Utils::HashSanitizer.sanitize(
          context,
          Appsignal.config[:filter_parameters]
        )
      end

      def self.formatted_metadata(job)
        job.map { |k, v| [k, truncate(string_or_inspect(v))] }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pallets-0.11.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.10.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.9.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.8.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.7.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.6.0 lib/pallets/middleware/appsignal_instrumenter.rb
pallets-0.5.1 lib/pallets/middleware/appsignal_instrumenter.rb