File Coverage

blib/lib/Sentry/Integration/LwpUserAgent.pm
Criterion Covered Total %
statement 36 36 100.0
branch 7 12 58.3
condition 3 6 50.0
subroutine 5 5 100.0
pod 0 1 0.0
total 51 60 85.0


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