| 1 | package PerlGuard::Agent::Monitors::NetHTTP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use PerlGuard::Agent::LexWrap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | extends 'PerlGuard::Agent::Monitors'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | has requests_in_progress => ( is => 'rw', default => sub { {} }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub die_unless_suitable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
die_unless_suitable: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | eval 'use Net::HTTP::Methods; use LWP::UserAgent; 1' or die "Could not load modules required for NetHTTP monitoring"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub start_monitoring { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_monitoring: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $simple_request_wrapper = wrap 'LWP::UserAgent::simple_request', pre => $self->simple_request_wrapper_sub(); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $simple_response_wrapper = wrap 'LWP::UserAgent::simple_request', post => $self->simple_response_wrapper_sub(); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | push(@{$self->overrides}, $simple_request_wrapper); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | push(@{$self->overrides}, $simple_response_wrapper); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub stop_monitoring { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop_monitoring: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | foreach my $override(@{$self->overrides}) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | undef $override; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub inform_agent_of_event { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inform_agent_of_event: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $trace = shift; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->agent->add_webservice_transaction($trace); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub simple_response_wrapper_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_response_wrapper_sub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $request = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $response = $_[4]; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $request_id = $request->header('X-PerlGuard-Auto-Track'); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return unless $request_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $trace = $self->requests_in_progress->{$request_id}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | unless($trace) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | #warn "Could not find a transaction trace matching the request\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $trace->{finish_time} = [Time::HiRes::gettimeofday()]; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $trace->{status_code} = $response->code(); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $trace->{status_message} = $response->message(); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->inform_agent_of_event($trace); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | delete $self->requests_in_progress->{$request_id}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # What we want to do is stash a unique value in a header so that we can | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # A) Link this up with its response later | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # B) Use it as the unique ID for cross application tracing | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub simple_request_wrapper_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_request_wrapper_sub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | #Determine if we are ok to log | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unless($self && $self->agent && $self->agent->current_profile()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self and $self->agent and $self->agent->current_profile
$self and $self->agent
MC/DC0%0/3
$self and $self->agent and $self->agent->current_profile
$self
$self->agent
$self->agent->current_profile
Truth table0%0/4
A and B and C
A= $selfB= $self->agentC= $self->agent->current_profile
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | #warn "Could not associate HTTP request with a profile, perhaps this request happened outside of the request"; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $profile = $self->agent->current_profile(); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $request = $_[0]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $request_id = $profile->generate_new_cross_application_tracing_id(); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $request->header( 'X-PerlGuard-Auto-Track' => $request_id ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $uri = blessed($request->uri) ? $request->uri->as_string : $request->uri; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->requests_in_progress->{$request_id} = { | |||||||||||||||||||||||||||||||||||||||||
| 98 | cross_application_tracing_id => $request_id, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | start_time => [Time::HiRes::gettimeofday()], | ||||||||||||||||||||||||||||||||||||||||||
| 100 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | method => $request->method, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||