From dc8e2b4c3e3a9a14c65f25ba59b4415cdf00c7e2 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 21 Jul 2015 12:53:46 +0800 Subject: Bug 1184001 - deliver error report to sentry via cron instead of immediately --- Bugzilla/Sentry.pm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'Bugzilla/Sentry.pm') diff --git a/Bugzilla/Sentry.pm b/Bugzilla/Sentry.pm index 4206118da..73f316a1d 100644 --- a/Bugzilla/Sentry.pm +++ b/Bugzilla/Sentry.pm @@ -17,9 +17,9 @@ our @EXPORT = qw( ); use Carp; -use Data::Dumper; use DateTime; use File::Temp; +use JSON (); use LWP::UserAgent; use Sys::Hostname; use URI; @@ -215,10 +215,11 @@ sub sentry_handle_error { if exists $ENV{$field}; } + my $now = DateTime->now(); my $data = { event_id => $id, message => $message, - timestamp => DateTime->now->iso8601(), + timestamp => $now->iso8601(), level => $level, platform => 'Other', logger => $logger, @@ -235,17 +236,19 @@ sub sentry_handle_error { }, }; - my $fh = File::Temp->new( UNLINK => 0 ); + my $fh = File::Temp->new( + DIR => bz_locations()->{error_reports}, + TEMPLATE => $now->ymd('') . $now->hms('') . '-XXXX', + SUFFIX => '.dump', + UNLINK => 0, + + ); if (!$fh) { - warn "Failed to create temp file: $!\n"; + warn "Failed to create dump file: $!\n"; return; } - print $fh Dumper($data); - close($fh) or die $!; - my $filename = $fh->filename; - - my $command = bz_locations()->{'cgi_path'} . "/sentry.pl '$filename' &"; - system($command); + print $fh JSON->new->utf8(1)->pretty(0)->allow_nonref(1)->encode($data); + close($fh); return 1; } @@ -259,7 +262,7 @@ sub _write_to_error_log { Apache2::ServerRec::warn($message); } } else { - print STDERR "$message\n"; + print STDERR $message, "\n"; } } -- cgit v1.2.3-24-g4f1b