Sha256: 39bfd519e492264fd905f6b408ab25b860a2a52df3381aaa99e4961a5ae9a1b3

Contents?: true

Size: 1.58 KB

Versions: 34

Compression:

Stored size: 1.58 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_sample_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'],
        Appsignal::Utils.json_generate(@data['backtrace'])
      )
    end

    def set_sample_data
      {
        :params       => @data['params'],
        :environment  => @data['environment'],
        :tags         => @data['tags']
      }.each do |key, data|
        next unless data.is_a?(Array) || data.is_a?(Hash)
        begin
          Appsignal::Extension.set_transaction_sample_data(
            @transaction_index,
            key.to_s,
            Appsignal::Utils.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)
      Appsignal::Extension.complete_transaction(@transaction_index)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
appsignal-1.2.0.alpha.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.7.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.6 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.6.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.5 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.5.beta.4 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.5.beta.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.5.beta.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.5.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.4 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.4.beta.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.4.beta.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.4.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.3.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.1.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.0.beta.13 lib/appsignal/js_exception_transaction.rb
appsignal-1.1.0.beta.12 lib/appsignal/js_exception_transaction.rb