Sha256: b382fd712ca279b7107699556b88ca5b84e75f78bb0f0fca78fd13f82889274b

Contents?: true

Size: 1.29 KB

Versions: 35

Compression:

Stored size: 1.29 KB

Contents

module Appsignal
  class JSExceptionTransaction
    attr_reader :uuid, :ext

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

      set_action
      set_metadata
      set_error
      set_sample_data
    end

    def set_action
      @ext.set_action(@data['action'])
    end

    def set_metadata
      @ext.set_metadata(
        'path', @data['path']
      ) if @data['path']
    end

    def set_error
      @ext.set_error(
        @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
          @ext.set_sample_data(
            key.to_s,
            Appsignal::Utils.json_generate(data)
          )
        rescue *Appsignal::Transaction::JSON_EXCEPTIONS => e
          Appsignal.logger.error("Error generating JSON (#{e.class}: #{e.message}) for '#{backtrace.inspect}'")
        end
      end
    end

    def complete!
      @ext.finish
      @ext.complete
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
appsignal-1.3.6.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.5 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.5.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.4 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.4.0.alpha.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.4.0.alpha.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.0 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.0.beta.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.0.beta.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.3.0.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.5 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.4 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.4.beta.4 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.4.beta.3 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.4.beta.2 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.4.beta.1 lib/appsignal/js_exception_transaction.rb
appsignal-1.2.3 lib/appsignal/js_exception_transaction.rb