OpenTelemetry/Instrumentation.pm

filter: Statementstmt 100% 72 / 72 Branchbran 76.9% 20 / 26 Conditioncond 55.5% 10 / 18 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 87.5% 14 / 16 Podpod 66.6% 2 / 3 totaltotal 82.1% 120 / 146 CC 26 SCAR 21.6
CC
26
Cov
88%
import
15.4
find_instrumentations
11.0
unimport
3.1
CRAP 8.7
« OpenTelemetry/Instrumentation/DBI.pm ↑ Summary OpenTelemetry/Attributes.pm »
1 package OpenTelemetry::Instrumentation;
2 # ABSTRACT: Top-level interface for OpenTelemetry instrumentations
3  
4 3 our $VERSION = '0.040';
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use List::Util 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Module::Pluggable search_path => [qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 OpenTelemetry::Instrumentation
15 OpenTelemetry::Integration
16 3 )];
17 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Ref::Util qw( is_coderef is_hashref is_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use OpenTelemetry::Common ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 my $logger = OpenTelemetry::Common::internal_logger;
22  
23 # To be overriden by instrumentations
24 0 ▶sub dependencies { }
Subroutine dependencies: not called CC=1 SCAR=0.0
Pod documented
25 0 ▶sub uninstall { } # experimental
Subroutine uninstall: not called CC=1 SCAR=0.0
Pod undocumented
26  
27 3 my %REGISTRY;
28 7 ▶my sub find_instrumentations {
Subroutine find_instrumentations: called CC=9 SCAR=24.0
29 7 my $class = shift;
30 7 ▶ return if %REGISTRY; # Runs once and caches results
Branch: 1 branch
BranchTrueFalseTotal
if %REGISTRY 6 1 7
31  
32 # Inlined from OpenTelemetry::Common to read Perl-specific config
33 1 ▶ my $legacy_support = $ENV{OTEL_PERL_USE_LEGACY_INSTRUMENTATIONS} // 1;
Condition50%1/2
$ENV{"OTEL_PERL_USE_LEGACY_INSTRUMENTATIONS"} // 1
l!l
01
MC/DC0%0/1
$ENV{"OTEL_PERL_USE_LEGACY_INSTRUMENTATIONS"} // 1
$ENV{"OTEL_PERL_USE_LEGACY_INSTRUMENTATIONS"}
Truth table50%1/2
A
A= $ENV{"OTEL_PERL_USE_LEGACY_INSTRUMENTATIONS"}
Aresult
11
00
34 1 ▶ $legacy_support
Branch: 2 branches
BranchTrueFalseTotal
$legacy_support =~ /^true$/i ? : 0 1 1
$legacy_support =~ /^false$/i ? : 0 1 1
35 = $legacy_support =~ /^true$/i ? 1
36 : $legacy_support =~ /^false$/i ? 0
37 : $legacy_support;
38  
39 # We sort the plugins so that we prefer the Instrumentation namespace
40 1 for ( sort $class->plugins ) {
41 4 ▶ last if /^OpenTelemetry::Integration::/ && !$legacy_support;
Branch: 1 branch
BranchTrueFalseTotal
if /^OpenTelemetry::Integration::/ and not $legacy_support 0 4 4
Condition66%2/3
/^OpenTelemetry::Integration::/ and not $legacy_support
!ll&&!rl&&r
310
MC/DC0%0/2
/^OpenTelemetry::Integration::/ and not $legacy_support
/^OpenTelemetry::Integration::/ not $legacy_support
Truth table66%2/3
A and not(B)
A= /^OpenTelemetry::Integration::/B= not $legacy_support
ABresult
0X0
100
111
42 4 ▶ $REGISTRY{ s/^OpenTelemetry::(?:Instrumentation|Integration):://r } ||= $_
Condition33%1/3
$REGISTRY{s/^OpenTelemetry::(?:Instrumentation|Integration):://r} ||= $_
l!l&&r!l&&!r
040
MC/DC0%0/2
$REGISTRY{s/^OpenTelemetry::(?:Instrumentation|Integration):://r} ||= $_
$REGISTRY{s/^OpenTelemetry::(?:Instrumentation|Integration):://r} $_
Truth table33%1/3
A ||= B
A= $REGISTRY{s/^OpenTelemetry::(?:Instrumentation|Integration):://r}B= $_
ABresult
1X1
011
000
43 }
44  
45 1 return;
46 }
47  
48 6 ▶sub for_package ($class, $package, @) {
Subroutine for_package: called CC=2 SCAR=6.9
Pod documented
49 6 find_instrumentations($class);
50 6 ▶ $REGISTRY{$package // ''};
Condition100%2/2
$package // ""
l!l
51
MC/DC100%1/1
$package // ""
$package
Truth table100%2/2
A
A= $package
Aresult
11
00
51 }
52  
53 my @installed;
54 5 ▶sub import ( $class, @args ) {
Subroutine import: called CC=15 SCAR=27.4
55 5 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 4 5
56  
57 4 ▶ my $all = $args[0] =~ /^[:-]all$/ && shift @args;
Condition66%2/3
$args[0] =~ /^[:-]all$/ && shift @args
!ll&&!rl&&r
301
MC/DC50%1/2
$args[0] =~ /^[:-]all$/ && shift @args
$args[0] =~ /^[:-]all$/ shift @args
Truth table66%2/3
A && B
A= $args[0] =~ /^[:-]all$/B= shift @args
ABresult
0X0
100
111
58  
59 4 my %configuration;
60 4 ▶ while ( my $key = shift @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift @args) 2 4 6
61 2 ▶ my $options = is_hashref($args[0]) || is_arrayref($args[0])
Branch: 1 branch
BranchTrueFalseTotal
is_hashref($args[0]) || is_arrayref($args[0]) ? : 0 2 2
Condition33%1/3
is_hashref($args[0]) or is_arrayref($args[0])
l!l&&r!l&&!r
002
MC/DC0%0/2
is_hashref($args[0]) or is_arrayref($args[0])
is_hashref($args[0]) is_arrayref($args[0])
Truth table33%1/3
A or B
A= is_hashref($args[0])B= is_arrayref($args[0])
ABresult
1X1
011
000
62 ? shift @args : {};
63  
64 # Legacy namespace support. If we are loading an integration
65 # by name which does not exist in INC in the new namespace,
66 # but does exist in the legacy namespace, we use the legacy
67 # name instead.
68 2 my $instrumentation = $class->for_package($key);
69  
70 2 ▶ unless ( $instrumentation ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($instrumentation) 1 1 2
71 1 $logger->warn(
72 "Unable to load OpenTelemetry instrumentation for $key: Can't locate any suitable module in \@INC (you may need to install OpenTelemetry::Instrumentation::$key) (\@INC entries checked: @INC)",
73 );
74 1 next;
75 }
76  
77 1 $configuration{$instrumentation} = $options;
78 }
79  
80 4 ▶ if ($all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) 1 3 4
81 1 find_instrumentations($class);
82 1 ▶ $configuration{$_} //= {} for values %REGISTRY;
Condition50%1/2
$configuration{$_} //= {}
l!l
04
MC/DC0%0/1
$configuration{$_} //= {}
$configuration{$_}
Truth table50%1/2
A
A= $configuration{$_}
Aresult
11
00
83 }
84  
85 4 for my $package ( keys %configuration ) {
86 5 try {
87 5 $logger->tracef('Loading %s', $package);
88  
89 5 Module::Runtime::require_module($package);
90  
91 # We only load dependencies if we are not loading every module
92 4 ▶ unless ($all) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($all) 1 3 4
93 1 Module::Runtime::require_module($_) for $package->dependencies;
94 }
95  
96 4 my $config = $configuration{ $package };
97 4 ▶ my $ok = $package->install( is_hashref $config ? %$config : @$config );
Branch: 1 branch
BranchTrueFalseTotal
is_hashref($config) ? : 4 0 4
98  
99 4 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 1 3 4
100 1 push @installed, $package;
101 }
102 else {
103 3 $logger->tracef("$package did not install itself");
104 }
105  
106 }
107 catch ($e) {
108 # Just a warning, if we're loading everything then
109 # we shouldn't cause chaos just because something
110 # doesn't happen to be available.
111 1 $logger->warnf('Unable to load %s: %s', $package, $e);
112 }
113 }
114 }
115  
116 5 ▶sub unimport ( $class, @args ) {
Subroutine unimport: called CC=3 SCAR=11.2
117 5 ▶ @args = @installed unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 5 0 5
118 5 $_->uninstall for @args;
119 5 return;
120 }
121  
122 3 1;
« OpenTelemetry/Instrumentation/DBI.pm ↑ Summary OpenTelemetry/Attributes.pm »