Sha256: 8109a541080d013bf050fd23ee01ddaea95c9f3d77acf71ebb2756d434392f2a

Contents?: true

Size: 1.51 KB

Versions: 22

Compression:

Stored size: 1.51 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)

      set_base_data
      set_metadata
      set_error
      set_error_data
    end

    def set_base_data
      Appsignal::Extension.set_transaction_base_data(
        @transaction_index,
        'frontend',
        @data['action'],
        0
      )
    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

22 entries across 22 versions & 1 rubygems

Version Path
appsignal-0.12.beta.31 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.30 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.29 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.28 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.27 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.26 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.25 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.24 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.23 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.22 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.21 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.20 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.19 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.18 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.17 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.16 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.15 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.14 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.13 lib/appsignal/js_exception_transaction.rb
appsignal-0.12.beta.12 lib/appsignal/js_exception_transaction.rb