File Coverage

blib/lib/Sentry/Integration/DBI.pm
Criterion Covered Total %
statement 31 62 50.0
branch 0 14 0.0
condition 1 15 6.6
subroutine 6 9 66.6
pod 0 2 0.0
total 38 102 37.2


line stmt bran cond sub pod time code
1             package Sentry::Integration::DBI;
2 4     4   29 use Mojo::Base 'Sentry::Integration::Base', -signatures;
  4         7  
  4         31  
3              
4 4     4   621 use Mojo::Util qw(dumper monkey_patch);
  4         10  
  4         543  
5              
6             has breadcrumbs => 1;
7             has tracing => 1;
8              
9             # DBI is special. Classes are generated on-the-fly.
10 6     6 0 9 sub around ($package, $method, $cb) {
  6         19  
  6         12  
  6         9  
  6         10  
11             ## no critic (TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings, TestingAndDebugging::ProhibitProlongedStrictureOverride)
12 4     4   29 no strict 'refs';
  4         9  
  4         212  
13 4     4   22 no warnings 'redefine';
  4         8  
  4         3346  
14              
15 6         18 my $symbol = join('::', $package, $method);
16              
17 6         9 my $orig = \&{$symbol};
  6         58  
18 6     0   41 *{$symbol} = sub { $cb->($orig, @_) };
  6         24  
  0         0  
19              
20 6         17 return;
21             }
22              
23 3     3 0 6 sub setup_once ($self, $add_global_event_processor, $get_current_hub) {
  3         7  
  3         6  
  3         4  
  3         5  
24              
25 0           around(
26             'DBI::db',
27 0     0     do => sub ($orig, $dbh, $statement, @args) {
  0            
  0            
  0            
  0            
28 0         0 my $hub = $get_current_hub->();
29              
30 0         0 my $span;
31              
32 0 0 0     0 if ($self->tracing && (my $parent_span = $hub->get_scope()->get_span)) {
33 0         0 $span = $parent_span->start_child({
34             op => 'sql.query', description => $statement, });
35             }
36              
37 0         0 my $value = $orig->($dbh, $statement, @args);
38              
39 0 0       0 $hub->add_breadcrumb({
40             type => 'query', category => 'do', data => { sql => $statement }, })
41             if $self->breadcrumbs;
42              
43 0 0 0     0 if (defined $span && $self->tracing) {
44 0         0 $span->finish();
45             }
46              
47 0         0 return $value;
48             }
49 3         23 );
50              
51 3 0 33     14 return if (!$self->breadcrumbs && !$self->tracing);
52              
53 0           around(
54             'DBI::st',
55 0     0     execute => sub ($orig, $sth, @args) {
  0            
  0            
  0            
56 0           my $statement = $sth->{Statement};
57              
58 0           my $hub = $get_current_hub->();
59              
60 0           my $span;
61              
62 0 0 0       if ($self->tracing && (my $parent_span = $hub->get_scope()->get_span)) {
63 0           $span = $parent_span->start_child({
64             op => 'sql.query',
65             description => $statement,
66             data => { args => [@args], },
67             });
68             }
69              
70 0           my $value = $orig->($sth, @args);
71              
72 0 0         $hub->add_breadcrumb({
73             type => 'query',
74             category => 'execute',
75             data => { sql => $statement, args => [@args], },
76             })
77             if $self->breadcrumbs;
78              
79 0 0 0       if (defined $span && $self->tracing) {
80 0           $span->finish();
81             }
82              
83 0           return $value;
84             }
85 3         47 );
86             }
87              
88             1;