| 1 | package Punk::Plugin::OpenTelemetry; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Punk::OpenTelemetry (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my %STATE; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 48 | ▶ | sub _state { $STATE{ $_[0] } //= { declared => {}, installed => 0 } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_state: called CC=2 SCAR=6.9
Condition100%2/2
$STATE{$_[0]} //= {"declared", {}, "installed", 0}
MC/DC100%1/1
$STATE{$_[0]} //= {"declared", {}, "installed", 0}
$STATE{$_[0]}
Truth table100%2/2
A
A= $STATE{$_[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | sub state_for { $STATE{ $_[1] // $_[0] } } # a test and introspection seam | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state_for: called CC=2 SCAR=9.2
Pod
undocumented
Condition33%1/3
$_[1] // $_[0]
MC/DC0%0/2
$_[1] // $_[0]
$_[1]
$_[0]
Truth table33%1/3
A // B
A= $_[1]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 16 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | _install_keywords($caller); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 32 | ▶ | sub _install_keywords { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_keywords: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 32 | my ($pkg, $app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 32 | my $st = _state($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 32 | ▶ | return if $st->{keywords_installed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | ▶ | $app ||= $pkg->can('punk_app') ? $pkg->punk_app | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$app ||= $pkg->can("punk_app") ? $pkg->punk_app : Carp::croak("Punk::Plugin::OpenTelemetry: $pkg is not a Punk " . 'application - `use Punk` before ' . "`use Punk::Plugin::OpenTelemetry`")
MC/DC0%0/2
$app ||= $pkg->can("punk_app") ? $pkg->punk_app : Carp::croak("Punk::Plugin::OpenTelemetry: $pkg is not a Punk " . 'application - `use Punk` before ' . "`use Punk::Plugin::OpenTelemetry`")
$app
$pkg->can("punk_app") ? $pkg->punk_app : Carp::croak("Punk::Plugin::OpenTelemetry: $pkg is not a Punk " . 'application - `use Punk` before ' . "`use Punk::Plugin::OpenTelemetry`")
Truth table33%1/3
A ||= B
A= $appB= $pkg->can("punk_app") ? $pkg->punk_app : Carp::croak("Punk::Plugin::OpenTelemetry: $pkg is not a Punk " . 'application - `use Punk` before ' . "`use Punk::Plugin::OpenTelemetry`")
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | : Carp::croak("Punk::Plugin::OpenTelemetry: $pkg is not a Punk " | ||||||||||||||||||||||||||||||||||||||||||
| 30 | . "application - `use Punk` before " | ||||||||||||||||||||||||||||||||||||||||||
| 31 | . "`use Punk::Plugin::OpenTelemetry`"); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | $st->{keywords_installed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | ▶ | $app->install_kw(otel => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 12 | my (%opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | ▶ | return $st->{tracer} if !%opt && $st->{tracer}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not %opt and $st->{"tracer"}
MC/DC0%0/2
not %opt and $st->{"tracer"}
not %opt
$st->{"tracer"}
Truth table33%1/3
not(A) and B
A= not %optB= $st->{"tracer"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 12 | @{ $st->{declared} }{ keys %opt } = values %opt; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | }, __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | sub new { bless {}, $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | my ($self, $app, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 16 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | ▶ | my $pkg = $app->caller_class | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | or Carp::croak('Punk::Plugin::OpenTelemetry: the app has no caller class'); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | my $st = _state($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | _install_keywords($pkg, $app); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | $st->{app} = $app; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | $st->{opts} = $opts; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | $app->hook(after_dispatch => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | _tick($st) if $st->{built} && !$st->{disabled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$st->{"built"} and not $st->{"disabled"}
MC/DC0%0/2
$st->{"built"} and not $st->{"disabled"}
$st->{"built"}
not $st->{"disabled"}
Truth table33%1/3
A and not(B)
A= $st->{"built"}B= not $st->{"disabled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 16 | ▶ | $app->middleware(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | my ($inner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | ▶ | _build($st) unless $st->{built}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | return $inner; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $app->helper(otel => sub { $st->{tracer} }, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $app->helper(otel_meter => sub { $st->{meter} }, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $app->helper(otel_logs => sub { $st->{logs} }, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $app->helper(otel_span => sub { _current_span($_[0]) }, __PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # The server span for this request, as `emit` takes one. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # READ AND NEVER TAKEN. The response side unstashes the span to end it, and | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # unstashing CLEARS the slot - so a helper that used the same call would end | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # the request's span by looking at it, and the trace would lose its root. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub _current_span { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_current_span: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my ($c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $stash = eval { $c->stash } or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $ptr = $stash->{'punk.otel.span'}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | # Zero is the response side saying it has already taken the span. A record | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # emitted after the span ended is correlated with nothing rather than with | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # freed memory. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return undef unless defined $ptr && $ptr =~ /\A\d+\z/ && $ptr > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $ptr and $ptr =~ /\A\d+\z/ and $ptr > 0
defined $ptr and $ptr =~ /\A\d+\z/
MC/DC0%0/3
defined $ptr and $ptr =~ /\A\d+\z/ and $ptr > 0
defined $ptr
$ptr =~ /\A\d+\z/
$ptr > 0
Truth table0%0/4
A and B and C
A= defined $ptrB= $ptr =~ /\A\d+\z/C= $ptr > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # BORROWED, and blessed into the class that cannot free it. The same | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # pointer in a Punk::OpenTelemetry::Span would be freed when this handle | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # went out of scope, and the response side would then end a span that had | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # already gone back to the allocator. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return bless \$ptr, 'Punk::OpenTelemetry::SpanRef'; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | ▶ | sub _build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build: called CC=16 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 16 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | $st->{built} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | my $app = $st->{app}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 16 | ▶ | my $opts = $st->{opts} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'opts'} || {}
MC/DC0%0/1
$st->{'opts'} || {}
$st->{'opts'}
Truth table50%1/2
A
A= $st->{'opts'}
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 16 | my $cfg = $st->{config} = _resolve($app, $st, $opts); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 16 | ▶ | if (Punk::OpenTelemetry::Config::disabled($cfg)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $st->{disabled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | _diagnostic($app, $cfg); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | my $resource = Punk::OpenTelemetry::Resource::detect( | ||||||||||||||||||||||||||||||||||||||||||
| 110 | (defined $cfg->{service_name} | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ? (service_name => $cfg->{service_name}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 15 | ▶ | %{ $cfg->{resource_attributes} || {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$cfg->{'resource_attributes'} || {}
MC/DC0%0/1
$cfg->{'resource_attributes'} || {}
$cfg->{'resource_attributes'}
Truth table50%1/2
A
A= $cfg->{'resource_attributes'}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 15 | my ($sampler, $ratio) = _sampler($cfg); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 15 | my $tracer = $st->{tracer} = Punk::OpenTelemetry::Tracer->new( | |||||||||||||||||||||||||||||||||||||||||
| 117 | resource => $resource, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | scope_name => 'Punk::OpenTelemetry', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | scope_version => $Punk::OpenTelemetry::VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | schema_url => Punk::OpenTelemetry::Instrument::schema_url(), | ||||||||||||||||||||||||||||||||||||||||||
| 121 | scope_schema_url => Punk::OpenTelemetry::Instrument::schema_url(), | ||||||||||||||||||||||||||||||||||||||||||
| 122 | sampler => $sampler, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ratio => $ratio, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | $st->{exporter} = Punk::OpenTelemetry::Exporter->new( | ||||||||||||||||||||||||||||||||||||||||||
| 127 | (defined $cfg->{endpoint} ? (endpoint => $cfg->{endpoint}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 128 | (defined $cfg->{endpoints} ? (endpoints => $cfg->{endpoints}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 129 | (defined $cfg->{protocol} ? (protocol => $cfg->{protocol}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 130 | (defined $cfg->{headers} ? (headers => $cfg->{headers}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 131 | (defined $cfg->{compression} ? (compression => $cfg->{compression}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 132 | (defined $cfg->{timeout} ? (timeout => $cfg->{timeout} / 1000) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | (defined $cfg->{ua} ? (ua => $cfg->{ua}) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | $st->{meter} = Punk::OpenTelemetry::Meter->new( | ||||||||||||||||||||||||||||||||||||||||||
| 137 | resource => $resource, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | scope_name => 'Punk::OpenTelemetry', | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 15 | ▶ | temporality => $cfg->{temporality_preference} || 'cumulative', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$cfg->{'temporality_preference'} || 'cumulative'
MC/DC0%0/1
$cfg->{'temporality_preference'} || 'cumulative'
$cfg->{'temporality_preference'}
Truth table50%1/2
A
A= $cfg->{'temporality_preference'}
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | ) if _want($cfg, 'metrics'); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 15 | ▶ | $st->{logs} = Punk::OpenTelemetry::Logs->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | resource => $resource, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | scope_name => 'Punk::OpenTelemetry', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ) if _want($cfg, 'logs'); | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # THE APPLICATION'S OWN LOGGER IS THE LOGS SIGNAL. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | # | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # `$c->log->error(...)` is the whole interface. Punk hands this a copy of | ||||||||||||||||||||||||||||||||||||||||||
| 150 | # every record it emits and the context it was emitted against, and the | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # copy leaves here with the request's trace id on it. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # A tap and not a sink: the line still goes wherever it was going, so | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # turning telemetry on never takes an operator's logs away and a collector | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # outage never silences them. | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 15 | Punk::OpenTelemetry::Logs::install_tap($st->{logs}); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # THE METER GOES IN TOO, so the instrumentation can record the HTTP | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # duration histogram itself. Handed the object rather than a flag: without | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # it the instrumentation records nothing and does not even start the | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # clock, so a deployment with metrics off pays nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | $st->{points} = Punk::OpenTelemetry::Instrument::install($tracer, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | server => _want($cfg, 'server'), | ||||||||||||||||||||||||||||||||||||||||||
| 164 | client => _want($cfg, 'client'), | ||||||||||||||||||||||||||||||||||||||||||
| 165 | db => _want($cfg, 'db'), | ||||||||||||||||||||||||||||||||||||||||||
| 166 | metrics => _want($cfg, 'metrics'), | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 15 | ▶ | ($st->{meter} ? (meter => $st->{meter}) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 15 | $st->{installed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | _on_worker_start(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $tracer->resource_attr('service.instance.id', | |||||||||||||||||||||||||||||||||||||||||
| 173 | Punk::OpenTelemetry::Resource::instance_id()); | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | }); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 15 | _diagnostic($app, $cfg); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | ▶ | sub _join_loop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_join_loop: called CC=8 SCAR=25.3
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | $st->{joined} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | ▶ | my $cfg = $st->{config} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'config'} || {}
MC/DC0%0/1
$st->{'config'} || {}
$st->{'config'}
Truth table50%1/2
A
A= $st->{'config'}
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | ▶ | return if $cfg->{ua} || !$st->{exporter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cfg->{"ua"} or not $st->{"exporter"}
MC/DC50%1/2
$cfg->{"ua"} or not $st->{"exporter"}
$cfg->{"ua"}
not $st->{"exporter"}
Truth table66%2/3
A or not(B)
A= $cfg->{"ua"}B= not $st->{"exporter"}
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | return unless $INC{'Hyperman.pm'} && eval { require Fetch; 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"Hyperman.pm"} and eval {
do {
require Fetch;
1
}
}
MC/DC0%0/2
$INC{"Hyperman.pm"} and eval {
do {
require Fetch;
1
}
}
$INC{"Hyperman.pm"}
eval {
do {
require Fetch;
1
}
}
Truth table33%1/3
A and B
A= $INC{"Hyperman.pm"}B= eval {
do {
require Fetch;
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | my $loop = eval { Hyperman->loop } or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $ua = eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | Fetch->new(loop => $loop, timeout => $st->{exporter}{timeout}) | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | } or return; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $st->{exporter}{ua} = $ua; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | sub _start_processor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_processor: called CC=5 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | ▶ | return $st->{processor} if $st->{processor}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | my $cfg = $st->{config}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | my $delay = ($cfg->{bsp}{schedule_delay} || 5000) / 1000; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{'bsp'}{'schedule_delay'} || 5000
MC/DC0%0/1
$cfg->{'bsp'}{'schedule_delay'} || 5000
$cfg->{'bsp'}{'schedule_delay'}
Truth table50%1/2
A
A= $cfg->{'bsp'}{'schedule_delay'}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | my $tick; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $tick = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | flush($st); | |||||||||||||||||||||||||||||||||||||||||
| 203 | $st->{exporter}->_sleep($delay, $tick) | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if ($st->{processor} || '') eq 'timer'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$st->{'processor'} || ''
MC/DC0%0/1
$st->{'processor'} || ''
$st->{'processor'}
Truth table0%0/2
A
A= $st->{'processor'}
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | my $loop = eval { $st->{exporter}{ua}->loop }; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | if ($loop && eval { $loop->can('_ft_timer') }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$loop and eval {
do {
$loop->can("_ft_timer")
}
}
MC/DC0%0/2
$loop and eval {
do {
$loop->can("_ft_timer")
}
}
$loop
eval {
do {
$loop->can("_ft_timer")
}
}
Truth table66%2/3
A and B
A= $loopB= eval {
do {
$loop->can("_ft_timer")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $st->{processor} = 'timer'; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | $st->{exporter}->_sleep($delay, sub { $tick->() }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | else { $st->{processor} = 'per-request' } | |||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | return $st->{processor}; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 5 | ▶ | sub _tick { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tick: called CC=12 SCAR=31.6
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | my $t = $st->{tracer} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | ▶ | delete $st->{processor} if !$st->{joined} && _join_loop($st); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $st->{"joined"} and _join_loop($st)
MC/DC0%0/2
not $st->{"joined"} and _join_loop($st)
not $st->{"joined"}
_join_loop($st)
Truth table33%1/3
not(A) and B
A= not $st->{"joined"}B= _join_loop($st)
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | _start_processor($st) unless $st->{processor}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | ▶ | return if ($st->{processor} || '') eq 'timer'; # the timer has it | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$st->{'processor'} || ''
MC/DC0%0/1
$st->{'processor'} || ''
$st->{'processor'}
Truth table50%1/2
A
A= $st->{'processor'}
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | my $cfg = $st->{config}; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | ▶ | my $batch = $cfg->{bsp}{max_export_batch_size} || 512; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{'bsp'}{'max_export_batch_size'} || 512
MC/DC0%0/1
$cfg->{'bsp'}{'max_export_batch_size'} || 512
$cfg->{'bsp'}{'max_export_batch_size'}
Truth table50%1/2
A
A= $cfg->{'bsp'}{'max_export_batch_size'}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 5 | ▶ | my $delay = ($cfg->{bsp}{schedule_delay} || 5000) / 1000; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{'bsp'}{'schedule_delay'} || 5000
MC/DC0%0/1
$cfg->{'bsp'}{'schedule_delay'} || 5000
$cfg->{'bsp'}{'schedule_delay'}
Truth table50%1/2
A
A= $cfg->{'bsp'}{'schedule_delay'}
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | ▶ | $st->{last_flush} ||= time; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$st->{"last_flush"} ||= time
MC/DC0%0/1
$st->{"last_flush"} ||= time
$st->{"last_flush"}
Truth table50%1/2
A
A= $st->{"last_flush"}
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | ▶ | return if $t->queued < $batch && time - $st->{last_flush} < $delay; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t->queued < $batch and time - $st->{"last_flush"} < $delay
MC/DC0%0/2
$t->queued < $batch and time - $st->{"last_flush"} < $delay
$t->queued < $batch
time - $st->{"last_flush"} < $delay
Truth table33%1/3
A and B
A= $t->queued < $batchB= time - $st->{"last_flush"} < $delay
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $st->{last_flush} = time; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | flush($st); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: called CC=11 SCAR=25.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | return unless $st->{exporter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # ONE EVAL PER SIGNAL, not one around all three. | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # A single eval means the first signal that throws takes the other two | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # with it - and the drain that never ran leaves its records queued, so | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # they are not even lost loudly. That is how metrics failing to encode | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # silently stopped logs from being exported at all: two signals gone to | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # one broken encoder, with nothing in the output to say so. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | ▶ | eval { if (my $t = $st->{tracer}) { my $p = $t->drain; _send($st, traces => $p) if $p } 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | or do { $st->{exporter}{stats}{failures}++ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | ▶ | eval { if (my $m = $st->{meter}) { my $p = $m->collect; _send($st, metrics => $p) if $p } 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | or do { $st->{exporter}{stats}{failures}++ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | eval { if (my $l = $st->{logs}) { my $p = $l->drain; _send($st, logs => $p) if $p } 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | or do { $st->{exporter}{stats}{failures}++ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | ▶ | sub _send { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | my ($st, $signal, $payload, $attempt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | ▶ | $attempt //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attempt //= 0
MC/DC0%0/1
$attempt //= 0
$attempt
Truth table50%1/2
A
A= $attempt
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my $exp = $st->{exporter}; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 6 | my $stats = $exp->{stats}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | Punk::OpenTelemetry::Instrument::suppress_begin(); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | my ($bytes, $f); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | $bytes = $exp->encode($signal => $payload); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | $f = $exp->_attempt($signal, $bytes); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 267 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 6 | Punk::OpenTelemetry::Instrument::suppress_end(); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | ▶ | die $err if !$ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 6 | ▶ | return unless $f; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | ▶ | $f->on_ready(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | my ($fut) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 6 | my $res = eval { $fut->get }; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 6 | ▶ | my ($verdict, $after) = $res | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | ? $exp->_classify($res->status, $res->headers, $res->content) | ||||||||||||||||||||||||||||||||||||||||||
| 278 | : $exp->_classify(undef); | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 6 | ▶ | if ($verdict eq 'ok') { $stats->{exported}++ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | elsif ($verdict eq 'partial') { $stats->{exported}++; $stats->{partial}++ } | |||||||||||||||||||||||||||||||||||||||||
| 282 | elsif ($verdict eq 'permanent') { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | $stats->{rejected}++; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 3 | $stats->{dropped}++; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | ▶ | elsif ($attempt >= ($exp->{max_retries} // 5)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$exp->{"max_retries"} // 5
MC/DC0%0/1
$exp->{"max_retries"} // 5
$exp->{"max_retries"}
Truth table0%0/2
A
A= $exp->{"max_retries"}
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $stats->{failures}++; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $stats->{dropped}++; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $stats->{retries}++; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $wait = $exp->backoff($attempt + 1, $after); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $exp->_sleep($wait, sub { _send($st, $signal, $payload, $attempt + 1) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 16 | ▶ | sub _resolve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve: called CC=5 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 16 | my ($app, $st, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 16 | ▶ | my %kw = (%{ $st->{declared} || {} }, %$opts); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'declared'} || {}
MC/DC0%0/1
$st->{'declared'} || {}
$st->{'declared'}
Truth table50%1/2
A
A= $st->{'declared'}
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 16 | my $file; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 16 | ▶ | if (my $cfg = eval { $app->config }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | $file = $cfg->{otel} if ref $cfg eq 'HASH' && ref $cfg->{otel} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $cfg eq "HASH" and ref $cfg->{"otel"} eq "HASH"
MC/DC0%0/2
ref $cfg eq "HASH" and ref $cfg->{"otel"} eq "HASH"
ref $cfg eq "HASH"
ref $cfg->{"otel"} eq "HASH"
Truth table0%0/3
A and B
A= ref $cfg eq "HASH"B= ref $cfg->{"otel"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 16 | return Punk::OpenTelemetry::Config::resolve( | |||||||||||||||||||||||||||||||||||||||||
| 311 | \%kw, $file, Punk::OpenTelemetry::Config::from_env()); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 23 | ▶ | sub _sampler { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sampler: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 23 | my ($cfg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 23 | ▶ | my $name = $cfg->{sampler} // 'parentbased_always_on'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{"sampler"} // "parentbased_always_on"
MC/DC0%0/1
$cfg->{"sampler"} // "parentbased_always_on"
$cfg->{"sampler"}
Truth table50%1/2
A
A= $cfg->{"sampler"}
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 23 | my $arg = $cfg->{sampler_arg}; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 23 | ▶ | my $ratio = defined $arg && $arg =~ /^[0-9.]+$/ ? $arg + 0 : 1.0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $arg and $arg =~ /^[0-9.]+$/
MC/DC100%2/2
defined $arg and $arg =~ /^[0-9.]+$/
defined $arg
$arg =~ /^[0-9.]+$/
Truth table100%3/3
A and B
A= defined $argB= $arg =~ /^[0-9.]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 23 | ▶ | return ('always_off', $ratio) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq "always_off" or $name eq "parentbased_always_off"
MC/DC100%2/2
$name eq "always_off" or $name eq "parentbased_always_off"
$name eq "always_off"
$name eq "parentbased_always_off"
Truth table100%3/3
A or B
A= $name eq "always_off"B= $name eq "parentbased_always_off"
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | if $name eq 'always_off' || $name eq 'parentbased_always_off'; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 21 | ▶ | return ('always_on', $ratio) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | if $name eq 'always_on'; | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 20 | return ('parent_ratio', $ratio); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 90 | ▶ | sub _want { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_want: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 90 | my ($cfg, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 90 | ▶ | return 1 unless exists $cfg->{$what}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | return $cfg->{$what} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 16 | ▶ | sub _diagnostic { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_diagnostic: called CC=4 SCAR=14.7
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 16 | my ($app, $cfg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 16 | my $line = Punk::OpenTelemetry::Config::diagnostic($cfg); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 16 | ▶ | my $log = eval { $app->can('log') ? $app->log : undef }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # SUPPRESSED, because the log tap is live by now and this is the SDK | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # talking about itself. Everything the SDK does on its own behalf runs | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # inside the guard - otherwise its own boot line becomes a log record, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # which becomes an export, and its own report of a failed export becomes | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # another one. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # The operator still gets the line. It goes to the log exactly as before; | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # it just is not also telemetry about the telemetry. | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 16 | Punk::OpenTelemetry::Instrument::suppress_begin(); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 16 | ▶ | if ($log && $log->can('info')) { eval { $log->info($line) } } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$log and $log->can("info")
MC/DC0%0/2
$log and $log->can("info")
$log
$log->can("info")
Truth table33%1/3
A and B
A= $logB= $log->can("info")
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | else { warn "$line\n" } | |||||||||||||||||||||||||||||||||||||||||
| 350 | 16 | Punk::OpenTelemetry::Instrument::suppress_end(); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 16 | return $line; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 15 | ▶ | sub _on_worker_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_worker_start: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 15 | my ($cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 15 | ▶ | return 0 unless $INC{'Hyperman.pm'} && Hyperman->can('on_worker_start'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"Hyperman.pm"} and "Hyperman"->can("on_worker_start")
MC/DC0%0/2
$INC{"Hyperman.pm"} and "Hyperman"->can("on_worker_start")
$INC{"Hyperman.pm"}
"Hyperman"->can("on_worker_start")
Truth table33%1/3
A and B
A= $INC{"Hyperman.pm"}B= "Hyperman"->can("on_worker_start")
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 15 | Hyperman->on_worker_start($cb); | |||||||||||||||||||||||||||||||||||||||||
| 358 | 15 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | __END__ | ||||||||||||||||||||||||||||||||||||||||||