blib/lib/CGI/Application/Plugin/Sentry.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 38 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package CGI::Application::Plugin::Sentry;
2 use Mojo::Base -base, -signatures;
3  
4 use CGI::Application;
5 use Mojo::Util 'dumper';
6 use Sentry::SDK;
7  
8 CGI::Application->add_callback(
9 init => sub ($c, %) {
10 Sentry::SDK->init(
11 { dsn => 'fixme', release => '1.0.0', dist => '12345', });
12 }
13 );
14  
15 CGI::Application->add_callback(
16 error => sub ($c, $error) {
17 Sentry::SDK->capture_exception($error);
18 }
19 );
20  
21 CGI::Application->add_callback(
22 prerun => sub ($c, $rm) {
23 Sentry::Hub->get_current_hub()->push_scope();
24  
25 my $transaction = Sentry::SDK->start_transaction(
26 { name => $rm, op => 'http.server', },
27 {
28 request => {
29 url => $c->query->url(-full => 1),
30 method => $c->query->request_method,
31 query => { $c->query->Vars },
32 headers => { map { $_ => $c->query->http($_) } $c->query->http },
33 env => \%ENV,
34 }
35 }
36 );
37  
38 $c->param('__sentry__transaction', $transaction);
39  
40 Sentry::SDK->configure_scope(sub ($scope) {
41 $scope->set_span($transaction);
42 });
43 }
44 );
45  
46 CGI::Application->add_callback(
47 postrun => sub ($c, $body_ref) {
48 my $transaction = $c->param('__sentry__transaction');
49 $transaction->set_http_status(200); # FIXME
50 $transaction->finish();
51 }
52 );
53  
54 CGI::Application->add_callback(
55 teardown => sub ($c) {
56 Sentry::Hub->get_current_hub()->pop_scope();
57 }
58 );
59  
60 1;