Sha256: 403ccf334830312552f3c13c875bb02e6393cbd99d9ae2ebfeecdcc1fbf366e9

Contents?: true

Size: 1.48 KB

Versions: 28

Compression:

Stored size: 1.48 KB

Contents

module Appsignal
  class JSExceptionTransaction
    attr_reader :uuid, :transaction_index

    def initialize(data)
      @data = data
      @uuid = SecureRandom.uuid
      @transaction_index = Appsignal::Extension.start_transaction(@uuid, Appsignal::Transaction::FRONTEND)

      set_action
      set_metadata
      set_error
      set_error_data
    end

    def set_action
      Appsignal::Extension.set_transaction_action(@transaction_index, @data['action'])
    end

    def set_metadata
      Appsignal::Extension.set_transaction_metadata(
        @transaction_index, 'path', @data['path']
      ) if @data['path']
    end

    def set_error
      Appsignal::Extension.set_transaction_error(
        @transaction_index,
        @data['name'],
        @data['message']
      )
    end

    def set_error_data
      {
        :params       => @data['params'],
        :environment  => @data['environment'],
        :backtrace    => @data['backtrace'],
        :tags         => @data['tags']
      }.each do |key, data|
        next unless data.is_a?(Array) || data.is_a?(Hash)
        begin
          Appsignal::Extension.set_transaction_error_data(
            @transaction_index,
            key.to_s,
            JSON.generate(data)
          )
        rescue JSON::GeneratorError=>e
          Appsignal.logger.error("JSON generate error (#{e.message}) for '#{data.inspect}'")
        end
      end
    end

    def complete!
      Appsignal::Extension.finish_transaction(@transaction_index)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
appsignal-0.12.rc.9 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.rc.8 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.rc.7 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.rc.6 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.rc.5 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.54 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.53 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.52 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.51 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.50 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.49 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.48 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.47 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.46 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.45 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.44 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.43 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.42 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.41 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.40 lib/appsignal/js_exception_transaction.rb