File Coverage

blib/lib/Sentry/Integration/LwpUserAgent.pm
Criterion Covered Total %
statement 16 35 45.7
branch 0 12 0.0
condition 1 6 16.6
subroutine 4 5 80.0
pod 0 1 0.0
total 21 59 35.5


line stmt bran cond sub pod time code
1             use Mojo::Base 'Sentry::Integration::Base', -signatures;
2 4     4   24  
  4         5  
  4         21  
3             use Mojo::Util qw(dumper);
4 4     4   758 use Sentry::Util 'around';
  4         8  
  4         138  
5 4     4   20  
  4         7  
  4         1436  
6             has breadcrumbs => 1;
7             has tracing => 1;
8              
9             return if (!$self->breadcrumbs && !$self->tracing);
10 3     3 0 5  
  3         6  
  3         3  
  3         7  
  3         11  
11 3 0 33     12 around(
12             'LWP::UserAgent',
13 0           request => sub ($orig, $lwp, $request, @args) {
14              
15 0     0     my $url = $request->uri;
  0            
  0            
  0            
  0            
16              
17 0           # Exclude Requests to the Sentry server
18             return $orig->($lwp, $request, @args)
19             if $request->header('x-sentry-auth');
20 0 0          
21             my $hub = $get_current_hub->();
22             my $span;
23 0            
24 0           if ($self->tracing && (my $parent_span = $hub->get_scope()->get_span)) {
25             $span = $parent_span->start_child({
26 0 0 0       op => 'http',
27 0           name => 'My Transaction',
28             description => $request->method . ' ' . $request->uri,
29             data => {
30             url => $request->uri,
31             method => $request->method,
32             headers => $request->headers,
33             },
34             });
35             }
36              
37             my $result = $orig->($lwp, $request, @args);
38              
39 0           $hub->add_breadcrumb({
40             type => 'http',
41 0 0         category => 'LWP::UserAgent',
42             data => {
43             url => $request->uri,
44             method => $request->method,
45             status_code => $result->code,
46             }
47             })
48             if $self->breadcrumbs;
49              
50             if ($span) {
51             if ($result->code) {
52 0 0         $span->set_http_status($result->code);
53 0 0         }
54 0           $span->finish();
55             }
56 0            
57             return $result;
58             }
59 0           );
60             }
61 3         31  
62             1;