line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Sentry; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
42946
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
11337
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
3288
|
use Sentry::Raven; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.11; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has qw/sentry/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
|
|
|
|
|
|
my ($plugin, $app, $conf) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$plugin->sentry( Sentry::Raven->new(%$conf) ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper(sentry => sub { |
16
|
|
|
|
|
|
|
$plugin->sentry; |
17
|
|
|
|
|
|
|
}); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$app->helper(sentryCaptureMessage => sub { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $data = shift; |
22
|
|
|
|
|
|
|
my %p = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if (ref $data eq 'Mojo::Exception') { |
25
|
|
|
|
|
|
|
my $req = $self->req; |
26
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
map {$_->[1]} |
43
|
|
|
|
|
|
|
@{$data->lines_before} |
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
post_context => [ |
46
|
|
|
|
|
|
|
map {$_->[1]} |
47
|
|
|
|
|
|
|
@{$data->lines_after} |
48
|
|
|
|
|
|
|
], |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
]), |
51
|
|
|
|
|
|
|
%p, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} else { |
54
|
|
|
|
|
|
|
$plugin->sentry->capture_message( |
55
|
|
|
|
|
|
|
$data, |
56
|
|
|
|
|
|
|
%p, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
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. |