class AppsignalExporter

Constants

VERSION

Public Class Methods

new(api_key, app_id) click to toggle source
# File lib/appsignal-exporter.rb, line 7
def initialize(api_key, app_id)
  @api_key = api_key
  @app_id = app_id
  @output_path = Pathname.new("appsignal-export-#{Date.today.strftime('%Y-%m-%d')}")
end

Public Instance Methods

export_errors(params = {}) click to toggle source
# File lib/appsignal-exporter.rb, line 13
def export_errors(params = {})
  params = parse_params(params)
  @output_path.mkpath

  output_file = @output_path.join('errors.json')
  return if output_file.exist?

  error_samples_response = get('samples/errors', params)

  output_file.write(error_samples_response)

  error_samples_response['log_entries'].each do |entry|
    next if (output_file = @output_path.join("#{entry['id']}.json")).exist?

    error_sample_response = get("samples/#{entry['id']}")
    output_file.write(error_sample_response)
  end
end

Private Instance Methods

get(path, params = {}) click to toggle source
# File lib/appsignal-exporter.rb, line 34
def get(path, params = {})
  query_string = params.merge(token: @api_key).map { |key, value| "#{key}=#{value}" }.join('&')
  JSON.parse(RestClient.get("https://appsignal.com/api/#{@app_id}/#{path}.json?#{query_string}"))
end
parse_params(params) click to toggle source
# File lib/appsignal-exporter.rb, line 39
def parse_params(params)
  params[:since] = Time.utc(*params[:since].split(/\D/).map(&:to_i)).to_i if params.key?(:since)
  params[:before] = Time.utc(*params[:before].split(/\D/).map(&:to_i)).to_i if params.key?(:before)
  params
end