class Aws::Xray::Cause

Constants

MAX_BACKTRACE_SIZE

Public Class Methods

new(stack: [], message: nil, type: nil) click to toggle source
# File lib/aws/xray/cause.rb, line 6
def initialize(stack: [], message: nil, type: nil)
  @id = SecureRandom.hex(8)
  @working_directory = (Dir.pwd + '/') rescue '/'
  @stack = stack
  @message = message
  @type = type
end

Public Instance Methods

build_stack(stack, dir) click to toggle source
# File lib/aws/xray/cause.rb, line 32
def build_stack(stack, dir)
  truncated = [stack.size - MAX_BACKTRACE_SIZE, 0].max
  stack = stack[0..MAX_BACKTRACE_SIZE - 1].map do |s|
    file, line, method_name = s.split(':')
    {
      path: file.sub(dir, ''),
      line: line,
      label: method_name,
    }
  end
  return truncated, stack
end
to_h(remote: false) click to toggle source
# File lib/aws/xray/cause.rb, line 14
def to_h(remote: false)
  truncated, stack = build_stack(@stack, @working_directory)
  {
    working_directory: @working_directory,
    paths: [],
    exceptions: [
      {
        id: @id,
        message: @message,
        type: @type,
        remote: remote,
        truncated: truncated,
        stack: stack,
      },
  ],
  }
end