line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::ExceptionSentry; |
2
|
2
|
|
|
2
|
|
361748
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
184427
|
|
|
2
|
|
|
|
|
29
|
|
3
|
2
|
|
|
2
|
|
1779
|
use Sentry::Raven; |
|
2
|
|
|
|
|
110129
|
|
|
2
|
|
|
|
|
1021
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.01; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'sentry_raven'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
1
|
|
|
1
|
1
|
63
|
my ($self, $app, $config) = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$self->sentry_raven( |
13
|
|
|
|
|
|
|
Sentry::Raven->new(%$config) |
14
|
1
|
50
|
|
|
|
11
|
) if $config->{sentry_dsn}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$app->hook(before_render => sub { |
17
|
4
|
|
|
4
|
|
83650
|
my ($c, $args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# check if variable $raven |
20
|
4
|
50
|
|
|
|
17
|
return unless $self->sentry_raven; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# check if template is exception |
23
|
|
|
|
|
|
|
return unless defined $args->{template} |
24
|
4
|
100
|
100
|
|
|
67
|
&& $args->{template} eq 'exception'; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
6
|
$self->_exception($c, $args); |
27
|
1
|
|
|
|
|
5397
|
}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _exception { |
31
|
1
|
|
|
1
|
|
5
|
my ($self, $c, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
6
|
my ($file_name) = $c->stash('exception') =~ /at\s+(.*)\s+line/; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->sentry_raven->capture_message( |
36
|
|
|
|
|
|
|
$c->stash('exception'), |
37
|
|
|
|
|
|
|
Sentry::Raven->request_context( |
38
|
|
|
|
|
|
|
$c->req->url->to_string, |
39
|
|
|
|
|
|
|
method => $c->req->method, |
40
|
|
|
|
|
|
|
data => $c->req->body_params->to_string, |
41
|
|
|
|
|
|
|
query_string => $c->req->query_params->to_string, |
42
|
|
|
|
|
|
|
headers => { |
43
|
4
|
|
|
|
|
116
|
map { $_ => $c->req->headers->header($_) } @{$c->req->headers->names} |
|
1
|
|
|
|
|
387
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
), |
46
|
|
|
|
|
|
|
Sentry::Raven->stacktrace_context( |
47
|
|
|
|
|
|
|
[ |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
filename => $file_name, |
50
|
|
|
|
|
|
|
function => $c->stash('action'), |
51
|
|
|
|
|
|
|
lineno => int($c->stash('exception')->line->[0]), |
52
|
|
|
|
|
|
|
context_line => $c->stash('exception')->line->[1], |
53
|
|
|
|
|
|
|
pre_context => [ |
54
|
5
|
|
|
|
|
25
|
map { $_->[1] } @{$c->stash('exception')->lines_before} |
|
1
|
|
|
|
|
142
|
|
55
|
|
|
|
|
|
|
], |
56
|
|
|
|
|
|
|
post_context => [ |
57
|
1
|
|
|
|
|
86
|
map { $_->[1] } @{$c->stash('exception')->lines_after} |
|
5
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
13
|
|
58
|
|
|
|
|
|
|
] |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
] |
61
|
|
|
|
|
|
|
) |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding utf8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Mojolicious::Plugin::ExceptionSentry - Sentry Plugin for Mojolicious |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Mojolicious::Lite |
76
|
|
|
|
|
|
|
plugin 'ExceptionSentry' => { |
77
|
|
|
|
|
|
|
sentry_dsn => 'https://<publickey>:<secretkey>@sentry.io/<projectid>' |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Mojolicious |
81
|
|
|
|
|
|
|
$self->plugin('ExceptionSentry' => { |
82
|
|
|
|
|
|
|
sentry_dsn => 'https://<publickey>:<secretkey>@sentry.io/<projectid>' |
83
|
|
|
|
|
|
|
}); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<Mojolicious::Plugin::ExceptionSentry> is a plugin for L<Mojolicious>, |
88
|
|
|
|
|
|
|
This module auto-send all exceptions from L<Mojolicious> for Sentry. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 OPTIONS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L<Mojolicious::Plugin::ExceptionSentry> supports the following options. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 sentry_dsn |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
plugin 'ExceptionSentry' => { |
97
|
|
|
|
|
|
|
sentry_dsn => 'DNS' |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The DSN for your sentry service. Get this from the client configuration page for your project. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 timeout |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
plugin 'ExceptionSentry' => { |
105
|
|
|
|
|
|
|
sentry_dsn => 'DNS', |
106
|
|
|
|
|
|
|
timeout => 5 |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Do not wait longer than this number of seconds when attempting to send an event. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SEE ALSO |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L<Sentry::Raven>, L<Mojolicious>, L<https://mojolicious.org>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Lucas Tiago de Moraes C<lucastiagodemoraes@gmail.com> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Lucas Tiago de Moraes. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |