enviar más información

This commit is contained in:
f 2020-12-07 15:27:24 -03:00
parent e53a560af0
commit baa7d58715
2 changed files with 8 additions and 10 deletions

View file

@ -3,8 +3,6 @@
module Api module Api
module V1 module V1
# Recibe notificaciones desde Airbrake # Recibe notificaciones desde Airbrake
#
# TODO: Autenticación
class NoticesController < BaseController class NoticesController < BaseController
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
@ -14,7 +12,7 @@ module Api
def create def create
if verify_api_key if verify_api_key
BacktraceJob.perform_later site_id: params[:site_id], BacktraceJob.perform_later site_id: params[:site_id],
errors: airbrake_params.map(&:permit!).map(&:to_h) params: airbrake_params.to_h
end end
render status: 201, json: { id: 1, url: root_url } render status: 201, json: { id: 1, url: root_url }
@ -25,7 +23,7 @@ module Api
# XXX: Por alguna razón Airbrake envía los datos con Content-Type: # XXX: Por alguna razón Airbrake envía los datos con Content-Type:
# text/plain. # text/plain.
def airbrake_params def airbrake_params
@airbrake_params ||= params.merge!(JSON.parse(request.raw_post) || {}).require(:errors) @airbrake_params ||= params.merge!(FastJsonparser.parse(request.raw_post) || {}).permit!
end end
def site def site

View file

@ -4,15 +4,15 @@
class BacktraceJob < ApplicationJob class BacktraceJob < ApplicationJob
queue_as :low_priority queue_as :low_priority
attr_reader :errors, :site_id attr_reader :params, :site_id
def perform(site_id:, errors:) def perform(site_id:, params:)
@site_id = site_id @site_id = site_id
@errors = errors @params = params
return if files.empty? return if files.empty?
errors.each do |error| params['errors'].each do |error|
error['backtrace'].each do |backtrace| error['backtrace'].each do |backtrace|
offset = SourceMap::Offset.new(backtrace['line'], backtrace['column']) offset = SourceMap::Offset.new(backtrace['line'], backtrace['column'])
mapping = sourcemap.bsearch(offset) mapping = sourcemap.bsearch(offset)
@ -28,7 +28,7 @@ class BacktraceJob < ApplicationJob
begin begin
raise NoMethodError raise NoMethodError
rescue NoMethodError => e rescue NoMethodError => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, errors: errors }) ExceptionNotifier.notify_exception(e, data: { site: site.name, params: params })
end end
end end
@ -40,7 +40,7 @@ class BacktraceJob < ApplicationJob
# Obtiene todos los archivos del backtrace # Obtiene todos los archivos del backtrace
def files def files
@files ||= errors.map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq.select { |x| x.start_with? site.url } @files ||= params['errors'].map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq.select { |x| x.start_with? site.url }
end end
# Asume que todos los sourcemaps comparten la misma URL, lo # Asume que todos los sourcemaps comparten la misma URL, lo