class XRay::Cause

Represents cause section in segment and subsegment document. It records information about application runtime exceptions.

Attributes

id[R]

Public Class Methods

new(exception: nil, id: nil, remote: false) click to toggle source
# File lib/aws-xray-sdk/model/cause.rb, line 10
def initialize(exception: nil, id: nil, remote: false)
  if exception
    @exception_h = normalize e: exception, remote: remote
  end
  @id = id
end

Public Instance Methods

to_h() click to toggle source
# File lib/aws-xray-sdk/model/cause.rb, line 17
def to_h
  return id if id
  h = {
    working_directory: Dir.pwd,
    paths:             Gem.paths.path,
    exceptions:        @exception_h
  }
  h
end
to_json() click to toggle source
# File lib/aws-xray-sdk/model/cause.rb, line 27
def to_json
  @to_json ||= begin
    MultiJson.dump to_h
  end
end

Private Instance Methods

normalize(e:, remote: false) click to toggle source
# File lib/aws-xray-sdk/model/cause.rb, line 35
def normalize(e:, remote: false)
  exceptions = []
  exceptions << normalize_exception(e: e, remote: remote)

  # don't propagate remote flag
  while e.cause
    exceptions << normalize_exception(e: e.cause)
    e = e.cause
  end

  exceptions
end
normalize_exception(e:, remote: false) click to toggle source
# File lib/aws-xray-sdk/model/cause.rb, line 48
def normalize_exception(e:, remote: false)
  h = {
    message: e.to_s,
    type:    e.class.to_s
  }
  h[:remote] = true if remote

  backtrace = e.backtrace_locations
  return h unless backtrace
  h[:stack] = backtrace.first(@@depth).collect do |t|
    {
      path:  t.path,
      line:  t.lineno,
      label: t.label
    }
  end

  truncated = backtrace.size - @@depth
  h[:truncated] = truncated if truncated > 0
  h
end