blib/lib/Sentry/Integration/LwpUserAgent.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 48 CC 6 SCAR 33.6
CC
6
Cov
0%
setup_once
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 28.7
1 package Sentry::Integration::LwpUserAgent;
2 use Mojo::Base 'Sentry::Integration::Base', -signatures;
3  
4 use Mojo::Util qw(dumper);
5 use Sentry::Util 'around';
6  
7 has breadcrumbs => 1;
8 has tracing => 1;
9  
10 sub setup_once ($self, $add_global_event_processor, $get_current_hub) {
11 return if (!$self->breadcrumbs && !$self->tracing);
12  
13 around(
14 'LWP::UserAgent',
15 request => sub ($orig, $lwp, $request, @args) {
16  
17 my $url = $request->uri;
18  
19 # Exclude Requests to the Sentry server
20 return $orig->($lwp, $request, @args)
21 if $request->header('x-sentry-auth');
22  
23 my $hub = $get_current_hub->();
24 my $span;
25  
26 if ($self->tracing && (my $parent_span = $hub->get_scope()->get_span)) {
27 $span = $parent_span->start_child({
28 op => 'http',
29 name => 'My Transaction',
30 description => $request->method . ' ' . $request->uri,
31 data => {
32 url => $request->uri,
33 method => $request->method,
34 headers => $request->headers,
35 },
36 });
37 }
38  
39 my $result = $orig->($lwp, $request, @args);
40  
41 $hub->add_breadcrumb({
42 type => 'http',
43 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 ($self->tracing) {
53  
54 # $span->set_http_status($tx->res->code);
55 $span->finish();
56 }
57  
58 return $result;
59 }
60 );
61 }
62  
63 1;