File Coverage

blib/lib/Sentry/Integration/MojoUserAgent.pm
Criterion Covered Total %
statement 31 35 88.5
branch 4 12 33.3
condition 2 6 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 42 59 71.1


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