File Coverage

blib/lib/Sentry/Integration/MojoUserAgent.pm
Criterion Covered Total %
statement 31 36 86.1
branch 4 12 33.3
condition 2 6 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 42 60 70.0


line stmt bran cond sub pod time code
1             use Mojo::Base 'Sentry::Integration::Base', -signatures;
2 4     4   24  
  4         9  
  4         31  
3             use Mojo::Util qw(dumper);
4 4     4   779 use Sentry::Util 'around';
  4         6  
  4         164  
5 4     4   33  
  4         7  
  4         1752  
6             has breadcrumbs => 1;
7             has tracing => 1;
8              
9             return if (!$self->breadcrumbs && !$self->tracing);
10 3     3 0 20  
  3         16  
  3         15  
  3         7  
  3         6  
11 3 0 33     15 around(
12             'Mojo::UserAgent',
13 2         5 start => sub ($orig, $ua, $tx, $cb = undef) {
14             my $url = $tx->req->url;
15 2     2   5  
  2         8  
  2         5  
  2         4  
  2         5  
16 2         19 # Exclude Requests to the Sentry server
17             return $orig->($ua, $tx, $cb)
18             if $tx->req->headers->header('x-sentry-auth');
19 2 50       15  
20             my $hub = $get_current_hub->();
21              
22 2         55 my $span;
23              
24 2         7 if ($self->tracing && (my $parent_span = $hub->get_scope()->get_span)) {
25             $span = $parent_span->start_child({
26 2 50 33     14 op => 'http.client',
27 0         0 description => $tx->req->method . ' ' . $tx->req->url->to_string,
28             data =>
29             { url => $tx->req->url->to_string, method => $tx->req->method, },
30             });
31              
32             $tx->req->headers->add('sentry-trace' => $span->to_trace_parent);
33             }
34 0         0  
35             my $result = $orig->($ua, $tx, $cb);
36              
37 2         26 $hub->add_breadcrumb({
38             type => 'http',
39 2 50       7893 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       16 $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         19 );
58             }
59 3         50  
60             1;