get backtrace emailed when code dies running underModPerl::RegistryPrefork?

get backtrace emailed when code dies running underModPerl::RegistryPrefork?

am 02.03.2009 15:54:47 von Matthew Lenz

As I've mentioned in previous posts, I'm migrating from an older
environment to a new environment with mod_perl 2.

With mod_perl 1.x we had VERY OLD customised version of CGI::Carp (with
fatalsToBrowser) printing an error to the browser AND sending an email
with backtrace and environment information when the code died with a
runtime errors.

According to the docs CGI::Carp doesn't function properly with
fatalToBrowser under mod_perl 2. The confusing thing is that right
below the fatalsToBrowser documentation it talks about set_die_handler.
Its not exactly clear as to whether set_die_handler doesn't work under
mod_perl 2 or not.

Is anyone using CGI::Carp for backtrace reporting? Is there an
alternative that someone knows about if CGI::Carp isn't an option?

Re: get backtrace emailed when code dies running under

am 02.03.2009 16:20:33 von Perrin Harkins

On Mon, Mar 2, 2009 at 9:54 AM, Matthew Lenz wrote:
> According to the docs CGI::Carp doesn't function properly with
> fatalToBrowser under mod_perl 2.

I'm not sure if that's accurate or not, but setting a $SIG{__DIE__}
handler should work fine. BTW, I assume you mean stacktrace, not
backtrace, which is usually associated with core dumps.

- Perrin

Re: get backtrace emailed when code dies running under ModPerl::RegistryPrefork?

am 02.03.2009 16:29:49 von Matthew Lenz

On Mon, 2009-03-02 at 10:20 -0500, Perrin Harkins wrote:
> On Mon, Mar 2, 2009 at 9:54 AM, Matthew Lenz wrote:
> > According to the docs CGI::Carp doesn't function properly with
> > fatalToBrowser under mod_perl 2.
>
> I'm not sure if that's accurate or not, but setting a $SIG{__DIE__}
> handler should work fine.

Isn't that basically what fatalsToBrowser does? You'd think that the
CGI/Carp developer(s) would have been able to get it working with
mod_perl 2.

I can try it though. Will sticking the $SIG{__DIE__} in the startup.pl
script be sufficient?

> BTW, I assume you mean stacktrace, not
> backtrace, which is usually associated with core dumps.

HAHA, yes. I was just getting ready to correct myself :) Thanks for
beating me to it.

> - Perrin

Re: get backtrace emailed when code dies running under ModPerl::RegistryPrefork?

am 02.03.2009 16:31:43 von mpeters

Perrin Harkins wrote:

> I'm not sure if that's accurate or not, but setting a $SIG{__DIE__}
> handler should work fine.

You don't even need to use a __DIE__ handler. mod_perl will place any runtime
errors into $r->notes('error-notes'). I don't like my errors going to the
browser (only really works if your content is HTML anyway) but for the email I
usually use an Apache cleanup handler. That way it gets sent after the client
request has returned, so they don't have to wait on it.

I use something like this:

# in httpd.conf where you need it
PerlCleanupHandler MyProject::ApacheCleanup

# in MyProject/ApacheCleanup.pm
package MyProject::ApacheCleanup;
use Apache::Constants qw(:common);
sub handler ($$) {
my ($class, $r) = @_;
return DECLINED unless $r->is_main;

my $status = $r->last->status;
return DECLINED unless $status == SERVER_ERROR;
my $error = $r->notes('error-notes') || $ENV{ERROR_NOTES};
return DECLINED unless $error;

# create your email message and send it. I also like to put in a
# Data::Dumper dump of %ENV, the URL, timestamp and other project
# specific config settings

return DECLINED;
}


--
Michael Peters
Plus Three, LP

Re: get backtrace emailed when code dies running under ModPerl::RegistryPrefork?

am 02.03.2009 16:59:18 von Adam Prime

Michael Peters wrote:
>
> You don't even need to use a __DIE__ handler. mod_perl will place any
> runtime errors into $r->notes('error-notes'). I don't like my errors
> going to the browser (only really works if your content is HTML anyway)
> but for the email I usually use an Apache cleanup handler. That way it
> gets sent after the client request has returned, so they don't have to
> wait on it.
>

This was news to me, so i went to the docs. According to them, you have
to explicitly enable this behavior. see:

http://perl.apache.org/docs/2.0/api/Apache2/Log.html#C_Apach e2__Const__LOG_TOCLIENT_

Is that still accurate?

Adam

Re: get backtrace emailed when code dies running under ModPerl::RegistryPrefork?

am 02.03.2009 17:39:11 von mpeters

Adam Prime wrote:

> This was news to me, so i went to the docs. According to them, you have
> to explicitly enable this behavior. see:
>
> http://perl.apache.org/docs/2.0/api/Apache2/Log.html#C_Apach e2__Const__LOG_TOCLIENT_
>
>
> Is that still accurate?

I don't know about mod_perl2, but I didn't have to do anything to have it
enabled under mod_perl1.

--
Michael Peters
Plus Three, LP