| 1 | package Mojolicious::Plugin::Sentry; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Sentry::Raven; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = 0.11; | |||||||||
| 7 | |||||||||||
| 8 | 1 | has qw/sentry/; | |||||||||
| 9 | |||||||||||
| 10 | 0 | ▶ | sub register { | ||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 11 | 0 | my ($plugin, $app, $conf) = @_; | |||||||||
| 12 | |||||||||||
| 13 | 0 | $plugin->sentry( Sentry::Raven->new(%$conf) ); | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | $app->helper(sentry => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | 0 | $plugin->sentry; | |||||||||
| 17 | 0 | }); | |||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | $app->helper(sentryCaptureMessage => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 20 | 0 | my $self = shift; | |||||||||
| 21 | 0 | my $data = shift; | |||||||||
| 22 | 0 | my %p = @_; | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | if (ref $data eq 'Mojo::Exception') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | my $req = $self->req; | |||||||||
| 26 | 0 | my ($filename, $lineno) = $data->message =~ /at\s+(.+?)\s+line\s+(\d+)/g; | |||||||||
| 27 | |||||||||||
| 28 | $plugin->sentry->capture_message( | ||||||||||
| 29 | $data->message, | ||||||||||
| 30 | $plugin->sentry->request_context( | ||||||||||
| 31 | $req->url->to_string, | ||||||||||
| 32 | method => $req->method, | ||||||||||
| 33 | data => $req->params->to_hash, | ||||||||||
| 34 | 0 | headers => { map {$_ => ~~$req->headers->header($_)} @{$req->headers->names} }, | |||||||||
| 35 | ), | ||||||||||
| 36 | $self->sentry->stacktrace_context([ | ||||||||||
| 37 | { | ||||||||||
| 38 | filename => $filename, | ||||||||||
| 39 | lineno => $data->line->[0], | ||||||||||
| 40 | context_line => $data->line->[1], | ||||||||||
| 41 | pre_context => [ | ||||||||||
| 42 | 0 | map {$_->[1]} | |||||||||
| 43 | 0 | @{$data->lines_before} | |||||||||
| 44 | ], | ||||||||||
| 45 | post_context => [ | ||||||||||
| 46 | 0 | map {$_->[1]} | |||||||||
| 47 | 0 | @{$data->lines_after} | |||||||||
| 48 | ], | ||||||||||
| 49 | } | ||||||||||
| 50 | ]), | ||||||||||
| 51 | %p, | ||||||||||
| 52 | ); | ||||||||||
| 53 | } else { | ||||||||||
| 54 | 0 | $plugin->sentry->capture_message( | |||||||||
| 55 | $data, | ||||||||||
| 56 | %p, | ||||||||||
| 57 | ); | ||||||||||
| 58 | } | ||||||||||
| 59 | 0 | }); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||
| 63 | |||||||||||
| 64 | =pod | ||||||||||
| 65 | |||||||||||
| 66 | =head1 NAME | ||||||||||
| 67 | |||||||||||
| 68 | Mojolicious::Plugin::Sentry - A perl sentry client for Mojolicious | ||||||||||
| 69 | |||||||||||
| 70 | =head1 VERSION | ||||||||||
| 71 | |||||||||||
| 72 | version 0.1 | ||||||||||
| 73 | |||||||||||
| 74 | =head1 SYNOPSIS | ||||||||||
| 75 | |||||||||||
| 76 | # Mojolicious::Lite | ||||||||||
| 77 | plugin 'sentry' => { | ||||||||||
| 78 | sentry_dsn => 'DSN', | ||||||||||
| 79 | server_name => 'HOSTNAME', | ||||||||||
| 80 | logger => 'root', | ||||||||||
| 81 | platform => 'perl', | ||||||||||
| 82 | }; | ||||||||||
| 83 | |||||||||||
| 84 | # Mojolicious with config | ||||||||||
| 85 | $self->plugin('sentry' => { | ||||||||||
| 86 | sentry_dsn => 'DSN', | ||||||||||
| 87 | server_name => 'HOSTNAME', | ||||||||||
| 88 | logger => 'root', | ||||||||||
| 89 | platform => 'perl', | ||||||||||
| 90 | }); | ||||||||||
| 91 | |||||||||||
| 92 | # template: tmpl/exception.html.ep | ||||||||||
| 93 | % sentryCaptureMessage $exception; | ||||||||||
| 94 | |||||||||||
| 95 | =head1 DESCRIPTION | ||||||||||
| 96 | |||||||||||
| 97 | Mojolicious::Plugin::Sentry is a plugin for the Mojolicious web framework which allow you use Sentry L<https://getsentry.com>. | ||||||||||
| 98 | |||||||||||
| 99 | See also L<Sentry::Raven|https://metacpan.org/pod/Sentry::Raven> for configuration parameters on init plugin and for use sentryCaptureMessage. | ||||||||||
| 100 | |||||||||||
| 101 | =head1 SEE ALSO | ||||||||||
| 102 | |||||||||||
| 103 | L<Sentry::Raven|https://metacpan.org/pod/Sentry::Raven> | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SOURCE REPOSITORY | ||||||||||
| 106 | |||||||||||
| 107 | L<https://github.com/likhatskiy/Mojolicious-Plugin-Sentry> | ||||||||||
| 108 | |||||||||||
| 109 | =head1 AUTHOR | ||||||||||
| 110 | |||||||||||
| 111 | Alexey Likhatskiy, <likhatskiy@gmail.com> | ||||||||||
| 112 | |||||||||||
| 113 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 114 | |||||||||||
| 115 | Copyright (C) 2014 "Alexey Likhatskiy" | ||||||||||
| 116 | |||||||||||
| 117 | This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. | ||||||||||