| 1 | package CGI::Application::Plugin::OpenTracing; | |||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 5 | ||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = 'v0.103.3'; | ||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use syntax 'maybe'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use OpenTracing::Implementation; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use OpenTracing::GlobalTracer; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Carp qw( croak carp ); | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use HTTP::Headers; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use HTTP::Status; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Scalar::Util qw( refaddr ); | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Time::HiRes qw( gettimeofday ); | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 18 | ||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use constant CGI_LOAD_TMPL => 'cgi_application_load_tmpl'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use constant CGI_REQUEST => 'cgi_application_request'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use constant CGI_RUN => 'cgi_application_run'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use constant CGI_SETUP => 'cgi_application_setup'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use constant CGI_TEARDOWN => 'cgi_application_teardown'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | our $implementation_import_name; | ||||||||||||||||||||||||||||||||||||||
| 26 | 5 | our @implementation_import_opts; | ||||||||||||||||||||||||||||||||||||||
| 27 | ||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | our $TAG_JOIN_CHAR = ','; | ||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||
| 30 | sub import { | |||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | my $package = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||
| 32 | ||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ( $implementation_import_name, @implementation_import_opts ) = @_; | ||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | $ENV{OPENTRACING_DEBUG} && carp "OpenTracing Implementation not defined during import\n" | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $CGI::Application::Plugin::OpenTracing::implementation_import_name || $ENV{'OPENTRACING_DEBUG'} && carp("OpenTracing Implementation not defined during import\n")
$ENV{"OPENTRACING_DEBUG"} and carp("OpenTracing Implementation not defined during import\n")
MC/DC0%0/3
defined $CGI::Application::Plugin::OpenTracing::implementation_import_name || $ENV{'OPENTRACING_DEBUG'} && carp("OpenTracing Implementation not defined during import\n")
defined $CGI::Application::Plugin::OpenTracing::implementation_import_name
$ENV{"OPENTRACING_DEBUG"}
carp("OpenTracing Implementation not defined during import\n")
Truth table0%0/4
A || B and C
A= defined $CGI::Application::Plugin::OpenTracing::implementation_import_nameB= $ENV{"OPENTRACING_DEBUG"}C= carp("OpenTracing Implementation not defined during import\n")
| ||||||||||||||||||||||||||||||||||||||||
| 35 | unless defined $implementation_import_name; | |||||||||||||||||||||||||||||||||||||||
| 36 | ||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | my $caller = caller; | ||||||||||||||||||||||||||||||||||||||
| 38 | 5 | $caller->add_callback( init => \&init ); | ||||||||||||||||||||||||||||||||||||||
| 39 | 5 | $caller->add_callback( prerun => \&prerun ); | ||||||||||||||||||||||||||||||||||||||
| 40 | 5 | $caller->add_callback( postrun => \&postrun ); | ||||||||||||||||||||||||||||||||||||||
| 41 | 5 | $caller->add_callback( load_tmpl => \&load_tmpl ); | ||||||||||||||||||||||||||||||||||||||
| 42 | 5 | $caller->add_callback( teardown => \&teardown ); | ||||||||||||||||||||||||||||||||||||||
| 43 | 5 | $caller->add_callback( error => \&error ); | ||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||
| 45 | ||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | my $run_glob = do { no strict 'refs'; \*{ $caller . '::run' } }; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | ▶ | my $run_orig | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 48 | = defined &$run_glob | |||||||||||||||||||||||||||||||||||||||
| 49 | ? \&run_glob | |||||||||||||||||||||||||||||||||||||||
| 50 | : eval "package $caller;" # SUPER works based on the package it's defined in | |||||||||||||||||||||||||||||||||||||||
| 51 | . 'sub { my $self = shift; $self->SUPER::run(@_) }'; | |||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | no warnings 'redefine'; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | *$run_glob = _wrap_run($run_orig); | ||||||||||||||||||||||||||||||||||||||
| 54 | ||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | return; | ||||||||||||||||||||||||||||||||||||||
| 56 | } | |||||||||||||||||||||||||||||||||||||||
| 57 | ||||||||||||||||||||||||||||||||||||||||
| 58 | sub _wrap_run { | |||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | my ($orig) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_run: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 60 | ||||||||||||||||||||||||||||||||||||||||
| 61 | return sub { | |||||||||||||||||||||||||||||||||||||||
| 62 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| ||||||||||||||||||||||||||||||||||||||||
| 63 | ||||||||||||||||||||||||||||||||||||||||
| 64 | 27 | my $res; | ||||||||||||||||||||||||||||||||||||||
| 65 | 27 | my $wantarray = wantarray; # eval has its own | ||||||||||||||||||||||||||||||||||||||
| 66 | 27 | my $ok = eval { | ||||||||||||||||||||||||||||||||||||||
| 67 | 27 | ▶ | if ($wantarray) { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $res = [ $cgi_app->$orig(@_) ]; | ||||||||||||||||||||||||||||||||||||||
| 69 | } | |||||||||||||||||||||||||||||||||||||||
| 70 | else { | |||||||||||||||||||||||||||||||||||||||
| 71 | 27 | $res = $cgi_app->$orig(@_); | ||||||||||||||||||||||||||||||||||||||
| 72 | } | |||||||||||||||||||||||||||||||||||||||
| 73 | 24 | 1; | ||||||||||||||||||||||||||||||||||||||
| 74 | }; | |||||||||||||||||||||||||||||||||||||||
| 75 | 27 | ▶ | return $wantarray ? @$res : $res if $ok; | |||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | my $error = $@; | ||||||||||||||||||||||||||||||||||||||
| 78 | ||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my $request_span = _plugin_get_scope($cgi_app, CGI_REQUEST)->get_span; | ||||||||||||||||||||||||||||||||||||||
| 80 | 3 | $request_span->add_tag('http.status_code' => 500); | ||||||||||||||||||||||||||||||||||||||
| 81 | ||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | _cascade_set_failed_spans($cgi_app, $error); | ||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | die $error; | ||||||||||||||||||||||||||||||||||||||
| 85 | 5 | }; | ||||||||||||||||||||||||||||||||||||||
| 86 | } | |||||||||||||||||||||||||||||||||||||||
| 87 | ||||||||||||||||||||||||||||||||||||||||
| 88 | sub _cascade_set_failed_spans { | |||||||||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | my ($cgi_app, $error, $root_span) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cascade_set_failed_spans: called CC=5 SCAR=16.1
| ||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | ▶ | my $root_addr = refaddr($root_span) if defined $root_span; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 91 | ||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | my $tracer = _plugin_get_tracer($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 93 | 5 | ▶ | while (my $scope = $tracer->get_scope_manager->get_active_scope()) { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 94 | 10 | my $span = $scope->get_span(); | ||||||||||||||||||||||||||||||||||||||
| 95 | 10 | ▶ | last if defined $root_addr and $root_addr eq refaddr($span); | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $root_addr and $root_addr eq builtin::refaddr($span)
MC/DC100%2/2
defined $root_addr and $root_addr eq builtin::refaddr($span)
defined $root_addr
$root_addr eq builtin::refaddr($span)
Truth table100%3/3
A and B
A= defined $root_addrB= $root_addr eq builtin::refaddr($span)
| ||||||||||||||||||||||||||||||||||||||||
| 96 | ||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | $span->add_tags(error => 1, message => $error); | ||||||||||||||||||||||||||||||||||||||
| 98 | 8 | $scope->close(); | ||||||||||||||||||||||||||||||||||||||
| 99 | } | |||||||||||||||||||||||||||||||||||||||
| 100 | 5 | return; | ||||||||||||||||||||||||||||||||||||||
| 101 | } | |||||||||||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||||||||||
| 103 | sub init { | |||||||||||||||||||||||||||||||||||||||
| 104 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||||||||
| 106 | 27 | _plugin_init_opentracing_implementation( $cgi_app ); | ||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||
| 108 | 27 | my %request_tags = _get_request_tags($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 109 | 27 | my %query_params = _get_query_params($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 110 | 27 | my %form_data = _get_form_data($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 111 | 27 | my $context = _tracer_extract_context( $cgi_app ); | ||||||||||||||||||||||||||||||||||||||
| 112 | ||||||||||||||||||||||||||||||||||||||||
| 113 | 27 | _plugin_start_active_span( $cgi_app, CGI_REQUEST, child_of => $context ); | ||||||||||||||||||||||||||||||||||||||
| 114 | 27 | _plugin_add_tags( $cgi_app, CGI_REQUEST, %request_tags ); | ||||||||||||||||||||||||||||||||||||||
| 115 | 27 | _plugin_add_tags( $cgi_app, CGI_REQUEST, %query_params ); | ||||||||||||||||||||||||||||||||||||||
| 116 | 27 | _plugin_add_tags( $cgi_app, CGI_REQUEST, %form_data ); | ||||||||||||||||||||||||||||||||||||||
| 117 | 27 | _plugin_start_active_span( $cgi_app, CGI_SETUP ); | ||||||||||||||||||||||||||||||||||||||
| 118 | ||||||||||||||||||||||||||||||||||||||||
| 119 | return | |||||||||||||||||||||||||||||||||||||||
| 120 | 27 | } | ||||||||||||||||||||||||||||||||||||||
| 121 | ||||||||||||||||||||||||||||||||||||||||
| 122 | ||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||
| 124 | sub prerun { | |||||||||||||||||||||||||||||||||||||||
| 125 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
prerun: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||
| 126 | ||||||||||||||||||||||||||||||||||||||||
| 127 | 27 | my %runmode_tags = _get_runmode_tags($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 128 | 27 | my %baggage_items = _get_baggage_items($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 129 | ||||||||||||||||||||||||||||||||||||||||
| 130 | 27 | _plugin_add_baggage_items( $cgi_app, CGI_SETUP, %baggage_items ); | ||||||||||||||||||||||||||||||||||||||
| 131 | 27 | _plugin_close_scope( $cgi_app, CGI_SETUP ); | ||||||||||||||||||||||||||||||||||||||
| 132 | 27 | _plugin_add_baggage_items( $cgi_app, CGI_REQUEST, %baggage_items ); | ||||||||||||||||||||||||||||||||||||||
| 133 | 27 | _plugin_add_tags( $cgi_app, CGI_REQUEST, %runmode_tags ); | ||||||||||||||||||||||||||||||||||||||
| 134 | 27 | _plugin_start_active_span( $cgi_app, CGI_RUN ); | ||||||||||||||||||||||||||||||||||||||
| 135 | ||||||||||||||||||||||||||||||||||||||||
| 136 | return | |||||||||||||||||||||||||||||||||||||||
| 137 | 27 | } | ||||||||||||||||||||||||||||||||||||||
| 138 | ||||||||||||||||||||||||||||||||||||||||
| 139 | ||||||||||||||||||||||||||||||||||||||||
| 140 | ||||||||||||||||||||||||||||||||||||||||
| 141 | sub postrun { | |||||||||||||||||||||||||||||||||||||||
| 142 | 24 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
postrun: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||
| 143 | ||||||||||||||||||||||||||||||||||||||||
| 144 | 24 | _plugin_close_scope( $cgi_app, CGI_RUN ); | ||||||||||||||||||||||||||||||||||||||
| 145 | 24 | _plugin_start_active_span( $cgi_app, CGI_TEARDOWN ); | ||||||||||||||||||||||||||||||||||||||
| 146 | ||||||||||||||||||||||||||||||||||||||||
| 147 | return | |||||||||||||||||||||||||||||||||||||||
| 148 | 24 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | ||||||||||||||||||||||||||||||||||||||||
| 150 | ||||||||||||||||||||||||||||||||||||||||
| 151 | ||||||||||||||||||||||||||||||||||||||||
| 152 | sub load_tmpl { | |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
load_tmpl: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||
| 154 | ||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | _plugin_close_scope( $cgi_app, CGI_LOAD_TMPL ); | ||||||||||||||||||||||||||||||||||||||
| 156 | ||||||||||||||||||||||||||||||||||||||||
| 157 | return | |||||||||||||||||||||||||||||||||||||||
| 158 | 0 | } | ||||||||||||||||||||||||||||||||||||||
| 159 | ||||||||||||||||||||||||||||||||||||||||
| 160 | ||||||||||||||||||||||||||||||||||||||||
| 161 | ||||||||||||||||||||||||||||||||||||||||
| 162 | sub teardown { | |||||||||||||||||||||||||||||||||||||||
| 163 | 24 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||
| 164 | ||||||||||||||||||||||||||||||||||||||||
| 165 | 24 | my %http_status_tags = _get_http_status_tags($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 166 | ||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | _plugin_close_scope( $cgi_app, CGI_TEARDOWN ); | ||||||||||||||||||||||||||||||||||||||
| 168 | 24 | _plugin_add_tags( $cgi_app, CGI_REQUEST, %http_status_tags ); | ||||||||||||||||||||||||||||||||||||||
| 169 | 24 | _plugin_close_scope( $cgi_app, CGI_REQUEST ); | ||||||||||||||||||||||||||||||||||||||
| 170 | ||||||||||||||||||||||||||||||||||||||||
| 171 | return | |||||||||||||||||||||||||||||||||||||||
| 172 | 24 | } | ||||||||||||||||||||||||||||||||||||||
| 173 | ||||||||||||||||||||||||||||||||||||||||
| 174 | ||||||||||||||||||||||||||||||||||||||||
| 175 | ||||||||||||||||||||||||||||||||||||||||
| 176 | sub error { | |||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | my ($cgi_app, $error) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | ▶ | return if not $cgi_app->error_mode(); # we're dying | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 179 | ||||||||||||||||||||||||||||||||||||||||
| 180 | # run span should continue | |||||||||||||||||||||||||||||||||||||||
| 181 | 2 | my $root = _plugin_get_scope($cgi_app, CGI_RUN)->get_span; | ||||||||||||||||||||||||||||||||||||||
| 182 | 2 | _cascade_set_failed_spans($cgi_app, $error, $root); | ||||||||||||||||||||||||||||||||||||||
| 183 | ||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | return; | ||||||||||||||||||||||||||||||||||||||
| 185 | } | |||||||||||||||||||||||||||||||||||||||
| 186 | ||||||||||||||||||||||||||||||||||||||||
| 187 | ||||||||||||||||||||||||||||||||||||||||
| 188 | ||||||||||||||||||||||||||||||||||||||||
| 189 | sub _init_global_tracer { | |||||||||||||||||||||||||||||||||||||||
| 190 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_global_tracer: called CC=2 SCAR=7.0
| ||||||||||||||||||||||||||||||||||||||||
| 191 | ||||||||||||||||||||||||||||||||||||||||
| 192 | 27 | my @bootstrap_options = _get_bootstrap_options($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 193 | ||||||||||||||||||||||||||||||||||||||||
| 194 | 27 | ▶ | my $bootstrapped_tracer = | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 195 | $implementation_import_name ? | |||||||||||||||||||||||||||||||||||||||
| 196 | OpenTracing::Implementation->bootstrap_tracer( | |||||||||||||||||||||||||||||||||||||||
| 197 | $implementation_import_name, | |||||||||||||||||||||||||||||||||||||||
| 198 | @implementation_import_opts, | |||||||||||||||||||||||||||||||||||||||
| 199 | @bootstrap_options, | |||||||||||||||||||||||||||||||||||||||
| 200 | ) | |||||||||||||||||||||||||||||||||||||||
| 201 | : | |||||||||||||||||||||||||||||||||||||||
| 202 | OpenTracing::Implementation->bootstrap_default_tracer( | |||||||||||||||||||||||||||||||||||||||
| 203 | @implementation_import_opts, | |||||||||||||||||||||||||||||||||||||||
| 204 | @bootstrap_options, | |||||||||||||||||||||||||||||||||||||||
| 205 | ) | |||||||||||||||||||||||||||||||||||||||
| 206 | ; | |||||||||||||||||||||||||||||||||||||||
| 207 | ||||||||||||||||||||||||||||||||||||||||
| 208 | 27 | OpenTracing::GlobalTracer->set_global_tracer( $bootstrapped_tracer ); | ||||||||||||||||||||||||||||||||||||||
| 209 | ||||||||||||||||||||||||||||||||||||||||
| 210 | return | |||||||||||||||||||||||||||||||||||||||
| 211 | 27 | } | ||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||
| 213 | ||||||||||||||||||||||||||||||||||||||||
| 214 | ||||||||||||||||||||||||||||||||||||||||
| 215 | sub _cgi_get_run_mode { | |||||||||||||||||||||||||||||||||||||||
| 216 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cgi_get_run_mode: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 217 | ||||||||||||||||||||||||||||||||||||||||
| 218 | 27 | my $run_mode = $cgi_app->get_current_runmode(); | ||||||||||||||||||||||||||||||||||||||
| 219 | ||||||||||||||||||||||||||||||||||||||||
| 220 | 27 | return $run_mode | ||||||||||||||||||||||||||||||||||||||
| 221 | } | |||||||||||||||||||||||||||||||||||||||
| 222 | ||||||||||||||||||||||||||||||||||||||||
| 223 | ||||||||||||||||||||||||||||||||||||||||
| 224 | ||||||||||||||||||||||||||||||||||||||||
| 225 | sub _cgi_get_run_method { | |||||||||||||||||||||||||||||||||||||||
| 226 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cgi_get_run_method: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 227 | ||||||||||||||||||||||||||||||||||||||||
| 228 | 27 | my $run_mode = $cgi_app->get_current_runmode(); | ||||||||||||||||||||||||||||||||||||||
| 229 | 27 | my $run_methode = { $cgi_app->run_modes }->{ $run_mode }; | ||||||||||||||||||||||||||||||||||||||
| 230 | ||||||||||||||||||||||||||||||||||||||||
| 231 | 27 | return $run_methode | ||||||||||||||||||||||||||||||||||||||
| 232 | } | |||||||||||||||||||||||||||||||||||||||
| 233 | ||||||||||||||||||||||||||||||||||||||||
| 234 | ||||||||||||||||||||||||||||||||||||||||
| 235 | ||||||||||||||||||||||||||||||||||||||||
| 236 | sub _cgi_get_http_method { | |||||||||||||||||||||||||||||||||||||||
| 237 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cgi_get_http_method: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 238 | ||||||||||||||||||||||||||||||||||||||||
| 239 | 27 | my $query = $cgi_app->query(); | ||||||||||||||||||||||||||||||||||||||
| 240 | ||||||||||||||||||||||||||||||||||||||||
| 241 | 27 | return $query->request_method(); | ||||||||||||||||||||||||||||||||||||||
| 242 | } | |||||||||||||||||||||||||||||||||||||||
| 243 | ||||||||||||||||||||||||||||||||||||||||
| 244 | ||||||||||||||||||||||||||||||||||||||||
| 245 | sub _cgi_get_http_headers { # TODO: extract headers from CGI request | |||||||||||||||||||||||||||||||||||||||
| 246 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cgi_get_http_headers: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 247 | 27 | return HTTP::Headers->new(); | ||||||||||||||||||||||||||||||||||||||
| 248 | } | |||||||||||||||||||||||||||||||||||||||
| 249 | ||||||||||||||||||||||||||||||||||||||||
| 250 | ||||||||||||||||||||||||||||||||||||||||
| 251 | sub _cgi_get_http_url { | |||||||||||||||||||||||||||||||||||||||
| 252 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_cgi_get_http_url: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 253 | ||||||||||||||||||||||||||||||||||||||||
| 254 | 27 | my $query = $cgi_app->query(); | ||||||||||||||||||||||||||||||||||||||
| 255 | ||||||||||||||||||||||||||||||||||||||||
| 256 | 27 | return $query->url(-path => 1); | ||||||||||||||||||||||||||||||||||||||
| 257 | } | |||||||||||||||||||||||||||||||||||||||
| 258 | ||||||||||||||||||||||||||||||||||||||||
| 259 | ||||||||||||||||||||||||||||||||||||||||
| 260 | ||||||||||||||||||||||||||||||||||||||||
| 261 | =for not_implemented | |||||||||||||||||||||||||||||||||||||||
| 262 | sub get_opentracing_global_tracer { | |||||||||||||||||||||||||||||||||||||||
| 263 | OpenTracing::GlobalTracer->get_global_tracer() | |||||||||||||||||||||||||||||||||||||||
| 264 | } | |||||||||||||||||||||||||||||||||||||||
| 265 | =cut | |||||||||||||||||||||||||||||||||||||||
| 266 | ||||||||||||||||||||||||||||||||||||||||
| 267 | ||||||||||||||||||||||||||||||||||||||||
| 268 | ||||||||||||||||||||||||||||||||||||||||
| 269 | sub _get_request_tags { | |||||||||||||||||||||||||||||||||||||||
| 270 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_request_tags: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 271 | ||||||||||||||||||||||||||||||||||||||||
| 272 | 27 | my %tags = ( | ||||||||||||||||||||||||||||||||||||||
| 273 | 'component' => 'CGI::Application', | |||||||||||||||||||||||||||||||||||||||
| 274 | maybe 'http.method' => _cgi_get_http_method($cgi_app), | |||||||||||||||||||||||||||||||||||||||
| 275 | maybe 'http.url' => _cgi_get_http_url($cgi_app), | |||||||||||||||||||||||||||||||||||||||
| 276 | ); | |||||||||||||||||||||||||||||||||||||||
| 277 | ||||||||||||||||||||||||||||||||||||||||
| 278 | ||||||||||||||||||||||||||||||||||||||||
| 279 | 27 | return %tags | ||||||||||||||||||||||||||||||||||||||
| 280 | } | |||||||||||||||||||||||||||||||||||||||
| 281 | ||||||||||||||||||||||||||||||||||||||||
| 282 | sub _gen_tag_processor { | |||||||||||||||||||||||||||||||||||||||
| 283 | 38 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_tag_processor: called CC=5 SCAR=16.1
| ||||||||||||||||||||||||||||||||||||||||
| 284 | ||||||||||||||||||||||||||||||||||||||||
| 285 | 38 | ▶ | my $joiner = sub { join $TAG_JOIN_CHAR, @_ }; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 286 | ||||||||||||||||||||||||||||||||||||||||
| 287 | 38 | my (@specs, $fallback); | ||||||||||||||||||||||||||||||||||||||
| 288 | 38 | foreach my $spec_gen (@_) { | ||||||||||||||||||||||||||||||||||||||
| 289 | 76 | ▶ | next if not defined $spec_gen; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 290 | ||||||||||||||||||||||||||||||||||||||||
| 291 | 28 | my ($spec, $spec_fallback) = _gen_spec($spec_gen->()); | ||||||||||||||||||||||||||||||||||||||
| 292 | 28 | ▶ | $fallback ||= $spec_fallback; | |||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$fallback ||= $spec_fallback
MC/DC100%2/2
$fallback ||= $spec_fallback
$fallback
$spec_fallback
Truth table100%3/3
A ||= B
A= $fallbackB= $spec_fallback
| ||||||||||||||||||||||||||||||||||||||||
| 293 | 28 | push @specs, $spec; | ||||||||||||||||||||||||||||||||||||||
| 294 | } | |||||||||||||||||||||||||||||||||||||||
| 295 | 38 | ▶ | $fallback ||= $joiner; | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$fallback ||= $joiner
MC/DC0%0/2
$fallback ||= $joiner
$fallback
$joiner
Truth table66%2/3
A ||= B
A= $fallbackB= $joiner
| ||||||||||||||||||||||||||||||||||||||||
| 296 | ||||||||||||||||||||||||||||||||||||||||
| 297 | return sub { | |||||||||||||||||||||||||||||||||||||||
| 298 | 73 | ▶ | my ($cgi_app, $name, $values) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| ||||||||||||||||||||||||||||||||||||||||
| 299 | ||||||||||||||||||||||||||||||||||||||||
| 300 | 73 | my $processor = $fallback; | ||||||||||||||||||||||||||||||||||||||
| 301 | 73 | foreach my $spec (@specs) { | ||||||||||||||||||||||||||||||||||||||
| 302 | 62 | my ($matched, $spec_processor) = $spec->($name); | ||||||||||||||||||||||||||||||||||||||
| 303 | 62 | ▶ | $processor = $spec_processor if $matched; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 304 | } | |||||||||||||||||||||||||||||||||||||||
| 305 | ||||||||||||||||||||||||||||||||||||||||
| 306 | 73 | ▶ | return if not defined $processor; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 307 | 64 | ▶ | return $processor if not ref $processor; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 308 | ||||||||||||||||||||||||||||||||||||||||
| 309 | 54 | ▶ | if (ref $processor eq 'CODE') { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 310 | 54 | my $processed = $processor->(@$values); | ||||||||||||||||||||||||||||||||||||||
| 311 | 54 | ▶ | $processed = $joiner->(@$processed) if ref $processed eq 'ARRAY'; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 312 | 54 | return $processed; | ||||||||||||||||||||||||||||||||||||||
| 313 | } | |||||||||||||||||||||||||||||||||||||||
| 314 | ||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | croak "Invalid processor for param `$name`: ", ref $processor; | ||||||||||||||||||||||||||||||||||||||
| 316 | 38 | }; | ||||||||||||||||||||||||||||||||||||||
| 317 | } | |||||||||||||||||||||||||||||||||||||||
| 318 | ||||||||||||||||||||||||||||||||||||||||
| 319 | sub _gen_spec { | |||||||||||||||||||||||||||||||||||||||
| 320 | 28 | ▶ | my @def = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_spec: called CC=6 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||
| 321 | ||||||||||||||||||||||||||||||||||||||||
| 322 | 28 | my $fallback; | ||||||||||||||||||||||||||||||||||||||
| 323 | 28 | ▶ | $fallback = pop @def if @def % 2 != 0; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 324 | ||||||||||||||||||||||||||||||||||||||||
| 325 | 28 | my (%direct_match, @regex); | ||||||||||||||||||||||||||||||||||||||
| 326 | 28 | ▶ | while (my ($cond, $processor) = splice @def, 0, 2) { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 327 | 33 | ▶ | if (ref $cond eq 'Regexp') { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | push @regex, [ $cond => $processor ]; | ||||||||||||||||||||||||||||||||||||||
| 329 | } | |||||||||||||||||||||||||||||||||||||||
| 330 | else { | |||||||||||||||||||||||||||||||||||||||
| 331 | 32 | ▶ | foreach my $name (ref $cond eq 'ARRAY' ? @$cond : $cond) { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 332 | 33 | $direct_match{$name} = $processor; | ||||||||||||||||||||||||||||||||||||||
| 333 | } | |||||||||||||||||||||||||||||||||||||||
| 334 | } | |||||||||||||||||||||||||||||||||||||||
| 335 | } | |||||||||||||||||||||||||||||||||||||||
| 336 | my $spec = sub { | |||||||||||||||||||||||||||||||||||||||
| 337 | 62 | ▶ | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||
| 338 | ||||||||||||||||||||||||||||||||||||||||
| 339 | # return match state separately to differentiate from undef processors | |||||||||||||||||||||||||||||||||||||||
| 340 | 62 | ▶ | return (1, $direct_match{$name}) if exists $direct_match{$name}; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 341 | ||||||||||||||||||||||||||||||||||||||||
| 342 | 34 | foreach (@regex) { | ||||||||||||||||||||||||||||||||||||||
| 343 | 3 | my ($re, $processor) = @$_; | ||||||||||||||||||||||||||||||||||||||
| 344 | 3 | ▶ | return (1, $processor) if $name =~ $re; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 345 | } | |||||||||||||||||||||||||||||||||||||||
| 346 | 31 | return; | ||||||||||||||||||||||||||||||||||||||
| 347 | 28 | }; | ||||||||||||||||||||||||||||||||||||||
| 348 | ||||||||||||||||||||||||||||||||||||||||
| 349 | 28 | return ($spec, $fallback); | ||||||||||||||||||||||||||||||||||||||
| 350 | } | |||||||||||||||||||||||||||||||||||||||
| 351 | ||||||||||||||||||||||||||||||||||||||||
| 352 | sub _get_query_params { | |||||||||||||||||||||||||||||||||||||||
| 353 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_query_params: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||
| 354 | ||||||||||||||||||||||||||||||||||||||||
| 355 | 27 | my $processor = _gen_tag_processor($cgi_app, | ||||||||||||||||||||||||||||||||||||||
| 356 | $cgi_app->can('opentracing_process_tags_query_params'), | |||||||||||||||||||||||||||||||||||||||
| 357 | $cgi_app->can('opentracing_process_tags'), | |||||||||||||||||||||||||||||||||||||||
| 358 | ); | |||||||||||||||||||||||||||||||||||||||
| 359 | ||||||||||||||||||||||||||||||||||||||||
| 360 | 27 | my %processed_params; | ||||||||||||||||||||||||||||||||||||||
| 361 | ||||||||||||||||||||||||||||||||||||||||
| 362 | 27 | my $query = $cgi_app->query(); | ||||||||||||||||||||||||||||||||||||||
| 363 | 27 | foreach my $param ($query->url_param()) { | ||||||||||||||||||||||||||||||||||||||
| 364 | 48 | ▶ | next unless defined $param; # huh ??? | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 365 | 48 | my @values = $query->url_param($param); | ||||||||||||||||||||||||||||||||||||||
| 366 | 48 | my $processed_value = $cgi_app->$processor($param, \@values); | ||||||||||||||||||||||||||||||||||||||
| 367 | 48 | ▶ | next unless defined $processed_value; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 368 | ||||||||||||||||||||||||||||||||||||||||
| 369 | 41 | $processed_params{"http.query.$param"} = $processed_value; | ||||||||||||||||||||||||||||||||||||||
| 370 | } | |||||||||||||||||||||||||||||||||||||||
| 371 | 27 | return %processed_params; | ||||||||||||||||||||||||||||||||||||||
| 372 | } | |||||||||||||||||||||||||||||||||||||||
| 373 | ||||||||||||||||||||||||||||||||||||||||
| 374 | sub _get_form_data { | |||||||||||||||||||||||||||||||||||||||
| 375 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_form_data: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||
| 376 | 27 | my $query = $cgi_app->query(); | ||||||||||||||||||||||||||||||||||||||
| 377 | 27 | ▶ | return unless _has_form_data($query); | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 378 | ||||||||||||||||||||||||||||||||||||||||
| 379 | 11 | my $processor = _gen_tag_processor($cgi_app, | ||||||||||||||||||||||||||||||||||||||
| 380 | $cgi_app->can('opentracing_process_tags_form_fields'), | |||||||||||||||||||||||||||||||||||||||
| 381 | $cgi_app->can('opentracing_process_tags'), | |||||||||||||||||||||||||||||||||||||||
| 382 | ); | |||||||||||||||||||||||||||||||||||||||
| 383 | ||||||||||||||||||||||||||||||||||||||||
| 384 | 11 | my %processed_params = (); | ||||||||||||||||||||||||||||||||||||||
| 385 | ||||||||||||||||||||||||||||||||||||||||
| 386 | 11 | my %params = $cgi_app->query->Vars(); | ||||||||||||||||||||||||||||||||||||||
| 387 | 11 | ▶ | while (my ($param_name, $param_value) = each %params) { | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 388 | 25 | my $processed_value = $cgi_app->$processor( | ||||||||||||||||||||||||||||||||||||||
| 389 | $param_name, [ split /\0/, $param_value ] | |||||||||||||||||||||||||||||||||||||||
| 390 | ); | |||||||||||||||||||||||||||||||||||||||
| 391 | 25 | ▶ | next unless defined $processed_value; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 392 | 21 | $processed_params{"http.form.$param_name"} = $processed_value | ||||||||||||||||||||||||||||||||||||||
| 393 | } | |||||||||||||||||||||||||||||||||||||||
| 394 | ||||||||||||||||||||||||||||||||||||||||
| 395 | 11 | return %processed_params; | ||||||||||||||||||||||||||||||||||||||
| 396 | } | |||||||||||||||||||||||||||||||||||||||
| 397 | ||||||||||||||||||||||||||||||||||||||||
| 398 | sub _has_form_data { | |||||||||||||||||||||||||||||||||||||||
| 399 | 27 | ▶ | my ($query) = @_; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_form_data: called CC=4 SCAR=14.5
| ||||||||||||||||||||||||||||||||||||||||
| 400 | 27 | my $content_type = $query->content_type(); | ||||||||||||||||||||||||||||||||||||||
| 401 | 27 | ▶ | return if not defined $content_type; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 402 | 11 | ▶ | return 1 if $content_type =~ m{\Amultipart/form-data}; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 403 | 11 | ▶ | return 1 if $content_type =~ m{\Aapplication/x-www-form-urlencoded}; | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return; | ||||||||||||||||||||||||||||||||||||||
| 405 | } | |||||||||||||||||||||||||||||||||||||||
| 406 | ||||||||||||||||||||||||||||||||||||||||
| 407 | sub _get_runmode_tags { | |||||||||||||||||||||||||||||||||||||||
| 408 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_runmode_tags: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 409 | ||||||||||||||||||||||||||||||||||||||||
| 410 | 27 | my %tags = ( | ||||||||||||||||||||||||||||||||||||||
| 411 | maybe 'run_mode' => _cgi_get_run_mode($cgi_app), | |||||||||||||||||||||||||||||||||||||||
| 412 | maybe 'run_method' => _cgi_get_run_method($cgi_app), | |||||||||||||||||||||||||||||||||||||||
| 413 | ); | |||||||||||||||||||||||||||||||||||||||
| 414 | 27 | return %tags | ||||||||||||||||||||||||||||||||||||||
| 415 | } | |||||||||||||||||||||||||||||||||||||||
| 416 | ||||||||||||||||||||||||||||||||||||||||
| 417 | sub _get_http_status_tags { | |||||||||||||||||||||||||||||||||||||||
| 418 | 24 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_http_status_tags: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||
| 419 | ||||||||||||||||||||||||||||||||||||||||
| 420 | 24 | my %headers = $cgi_app->header_props(); | ||||||||||||||||||||||||||||||||||||||
| 421 | my $status = $headers{-status} or return ( | |||||||||||||||||||||||||||||||||||||||
| 422 | 24 | ▶ | 'http.status_code' => '200', | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 423 | ); | |||||||||||||||||||||||||||||||||||||||
| 424 | 3 | my $status_code = [ $status =~ /^\s*(\d{3})/ ]->[0]; | ||||||||||||||||||||||||||||||||||||||
| 425 | 3 | my $status_mess = [ $status =~ /^\s*\d{3}\s*(.+)\s*$/ ]->[0]; | ||||||||||||||||||||||||||||||||||||||
| 426 | ||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | ▶ | $status_mess = HTTP::Status::status_message($status_code) | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 428 | unless defined $status_mess; | |||||||||||||||||||||||||||||||||||||||
| 429 | ||||||||||||||||||||||||||||||||||||||||
| 430 | 3 | my %tags = ( | ||||||||||||||||||||||||||||||||||||||
| 431 | maybe 'http.status_code' => $status_code, | |||||||||||||||||||||||||||||||||||||||
| 432 | maybe 'http.status_message' => $status_mess, | |||||||||||||||||||||||||||||||||||||||
| 433 | ); | |||||||||||||||||||||||||||||||||||||||
| 434 | 3 | return %tags | ||||||||||||||||||||||||||||||||||||||
| 435 | } | |||||||||||||||||||||||||||||||||||||||
| 436 | ||||||||||||||||||||||||||||||||||||||||
| 437 | ||||||||||||||||||||||||||||||||||||||||
| 438 | sub _get_bootstrap_options { | |||||||||||||||||||||||||||||||||||||||
| 439 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_bootstrap_options: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||
| 440 | ||||||||||||||||||||||||||||||||||||||||
| 441 | 27 | ▶ | return unless $cgi_app->can('opentracing_bootstrap_options'); | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 442 | ||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | my @bootstrap_options = $cgi_app->opentracing_bootstrap_options( ); | ||||||||||||||||||||||||||||||||||||||
| 444 | ||||||||||||||||||||||||||||||||||||||||
| 445 | return @bootstrap_options | |||||||||||||||||||||||||||||||||||||||
| 446 | 1 | } | ||||||||||||||||||||||||||||||||||||||
| 447 | ||||||||||||||||||||||||||||||||||||||||
| 448 | ||||||||||||||||||||||||||||||||||||||||
| 449 | ||||||||||||||||||||||||||||||||||||||||
| 450 | sub _get_baggage_items { | |||||||||||||||||||||||||||||||||||||||
| 451 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_baggage_items: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||
| 452 | ||||||||||||||||||||||||||||||||||||||||
| 453 | 27 | ▶ | return unless $cgi_app->can('opentracing_baggage_items'); | |||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||
| 454 | ||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | my %baggage_items = $cgi_app->opentracing_baggage_items( ); | ||||||||||||||||||||||||||||||||||||||
| 456 | ||||||||||||||||||||||||||||||||||||||||
| 457 | ||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | return %baggage_items | ||||||||||||||||||||||||||||||||||||||
| 459 | } | |||||||||||||||||||||||||||||||||||||||
| 460 | ||||||||||||||||||||||||||||||||||||||||
| 461 | ||||||||||||||||||||||||||||||||||||||||
| 462 | ||||||||||||||||||||||||||||||||||||||||
| 463 | sub _tracer_extract_context { | |||||||||||||||||||||||||||||||||||||||
| 464 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_tracer_extract_context: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 465 | ||||||||||||||||||||||||||||||||||||||||
| 466 | 27 | my $http_headers = _cgi_get_http_headers($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 467 | 27 | my $tracer = _plugin_get_tracer( $cgi_app ); | ||||||||||||||||||||||||||||||||||||||
| 468 | ||||||||||||||||||||||||||||||||||||||||
| 469 | 27 | return $tracer->extract_context($http_headers) | ||||||||||||||||||||||||||||||||||||||
| 470 | } | |||||||||||||||||||||||||||||||||||||||
| 471 | ||||||||||||||||||||||||||||||||||||||||
| 472 | sub _plugin_get_tracer { | |||||||||||||||||||||||||||||||||||||||
| 473 | 137 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_get_tracer: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 474 | return $cgi_app->{__PLUGINS}{OPENTRACING}{TRACER} | |||||||||||||||||||||||||||||||||||||||
| 475 | 137 | } | ||||||||||||||||||||||||||||||||||||||
| 476 | ||||||||||||||||||||||||||||||||||||||||
| 477 | sub _plugin_init_opentracing_implementation { | |||||||||||||||||||||||||||||||||||||||
| 478 | 27 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_init_opentracing_implementation: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 479 | ||||||||||||||||||||||||||||||||||||||||
| 480 | 27 | _init_global_tracer($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 481 | # unless OpenTracing::GlobalTracer->is_registered; | |||||||||||||||||||||||||||||||||||||||
| 482 | 27 | my $tracer = OpenTracing::GlobalTracer->get_global_tracer; | ||||||||||||||||||||||||||||||||||||||
| 483 | ||||||||||||||||||||||||||||||||||||||||
| 484 | 27 | $cgi_app->{__PLUGINS}{OPENTRACING}{TRACER} = $tracer; | ||||||||||||||||||||||||||||||||||||||
| 485 | } | |||||||||||||||||||||||||||||||||||||||
| 486 | ||||||||||||||||||||||||||||||||||||||||
| 487 | sub _plugin_start_active_span { | |||||||||||||||||||||||||||||||||||||||
| 488 | 105 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_start_active_span: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 489 | 105 | my $operation_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 490 | 105 | my %params = @_; | ||||||||||||||||||||||||||||||||||||||
| 491 | 105 | my $scope_name = uc $operation_name; | ||||||||||||||||||||||||||||||||||||||
| 492 | ||||||||||||||||||||||||||||||||||||||||
| 493 | 105 | my $scope = | ||||||||||||||||||||||||||||||||||||||
| 494 | _tracer_start_active_span( $cgi_app, $operation_name, %params ); | |||||||||||||||||||||||||||||||||||||||
| 495 | ||||||||||||||||||||||||||||||||||||||||
| 496 | 105 | $cgi_app->{__PLUGINS}{OPENTRACING}{SCOPE}{$scope_name} = $scope; | ||||||||||||||||||||||||||||||||||||||
| 497 | } | |||||||||||||||||||||||||||||||||||||||
| 498 | ||||||||||||||||||||||||||||||||||||||||
| 499 | sub _tracer_start_active_span { | |||||||||||||||||||||||||||||||||||||||
| 500 | 105 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_tracer_start_active_span: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 501 | 105 | my $operation_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 502 | 105 | my %params = @_; | ||||||||||||||||||||||||||||||||||||||
| 503 | ||||||||||||||||||||||||||||||||||||||||
| 504 | 105 | my $tracer = _plugin_get_tracer($cgi_app); | ||||||||||||||||||||||||||||||||||||||
| 505 | 105 | $tracer->start_active_span( $operation_name, %params ); | ||||||||||||||||||||||||||||||||||||||
| 506 | } | |||||||||||||||||||||||||||||||||||||||
| 507 | ||||||||||||||||||||||||||||||||||||||||
| 508 | sub _plugin_add_tags { | |||||||||||||||||||||||||||||||||||||||
| 509 | 132 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_add_tags: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 510 | 132 | my $operation_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 511 | 132 | my %tags = @_; | ||||||||||||||||||||||||||||||||||||||
| 512 | 132 | my $scope_name = uc $operation_name; | ||||||||||||||||||||||||||||||||||||||
| 513 | ||||||||||||||||||||||||||||||||||||||||
| 514 | 132 | $cgi_app->{__PLUGINS}{OPENTRACING}{SCOPE}{$scope_name} | ||||||||||||||||||||||||||||||||||||||
| 515 | ->get_span->add_tags(%tags); | |||||||||||||||||||||||||||||||||||||||
| 516 | } | |||||||||||||||||||||||||||||||||||||||
| 517 | ||||||||||||||||||||||||||||||||||||||||
| 518 | sub _plugin_add_baggage_items { | |||||||||||||||||||||||||||||||||||||||
| 519 | 54 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_add_baggage_items: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 520 | 54 | my $operation_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 521 | 54 | my %baggage_items = @_; | ||||||||||||||||||||||||||||||||||||||
| 522 | 54 | my $scope_name = uc $operation_name; | ||||||||||||||||||||||||||||||||||||||
| 523 | ||||||||||||||||||||||||||||||||||||||||
| 524 | 54 | $cgi_app->{__PLUGINS}{OPENTRACING}{SCOPE}{$scope_name} | ||||||||||||||||||||||||||||||||||||||
| 525 | ->get_span->add_baggage_items( %baggage_items ); | |||||||||||||||||||||||||||||||||||||||
| 526 | } | |||||||||||||||||||||||||||||||||||||||
| 527 | ||||||||||||||||||||||||||||||||||||||||
| 528 | sub _plugin_close_scope { | |||||||||||||||||||||||||||||||||||||||
| 529 | 99 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_close_scope: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 530 | 99 | my $operation_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 531 | 99 | my $scope_name = uc $operation_name; | ||||||||||||||||||||||||||||||||||||||
| 532 | ||||||||||||||||||||||||||||||||||||||||
| 533 | 99 | $cgi_app->{__PLUGINS}{OPENTRACING}{SCOPE}{$scope_name}->close | ||||||||||||||||||||||||||||||||||||||
| 534 | } | |||||||||||||||||||||||||||||||||||||||
| 535 | ||||||||||||||||||||||||||||||||||||||||
| 536 | sub _plugin_get_scope { | |||||||||||||||||||||||||||||||||||||||
| 537 | 5 | ▶ | my $cgi_app = shift; | |||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_get_scope: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||
| 538 | 5 | my $scope_name = shift; | ||||||||||||||||||||||||||||||||||||||
| 539 | 5 | return $cgi_app->{__PLUGINS}{OPENTRACING}{SCOPE}{uc $scope_name}; | ||||||||||||||||||||||||||||||||||||||
| 540 | } | |||||||||||||||||||||||||||||||||||||||
| 541 | ||||||||||||||||||||||||||||||||||||||||
| 542 | ||||||||||||||||||||||||||||||||||||||||
| 543 | 5 | 1; | ||||||||||||||||||||||||||||||||||||||