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