SDK/Resource.pm

filter: Statementstmt 65.2% 30 / 46 Branchbran 30.0% 3 / 10 Conditioncond 15.7% 3 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 87.5% 7 / 8 Podpod 50.0% 2 / 4 totaltotal 45.9% 45 / 98 CC 14 SCAR 29.8
CC
14
Cov
48%
merge
42.0
BUILDARGS
17.1
BEGIN
1.0
CRAP 19.6
↑ Summary SDK/Trace/Sampler/ParentBased.pm »
1 4 ▶use Object::Pad ':experimental(init_expr)';
Subroutine BEGIN: called CC=1 SCAR=0.0
2 # ABSTRACT: Represents the entity producing OpenTelemetry data
3 package OpenTelemetry::SDK::Resource;
4  
5 4 our $VERSION = '0.101';
6  
7 class OpenTelemetry::SDK::Resource :does(OpenTelemetry::Attributes) {
8 4 ▶ use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶ use OpenTelemetry::Common 'config';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶ use isa 'OpenTelemetry::SDK::Resource';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 my $logger = OpenTelemetry::Common::internal_logger;
14  
15 4 require OpenTelemetry::SDK; # For VERSION
16  
17 4 field $schema_url :param :reader //= '';
18  
19 1 ▶ sub empty { shift->new( empty => 1, @_ ) }
Subroutine empty: called CC=1 SCAR=0.0
Subroutine schema_url: called CC=1 SCAR=0.0
Pod documented
Pod undocumented
20  
21 10 ▶ sub BUILDARGS ( $class, %args ) {
Subroutine BUILDARGS: called CC=9 SCAR=28.4
Pod undocumented
22 10 ▶ return %args if delete $args{empty};
Branch: 1 branch
BranchTrueFalseTotal
if delete $args{"empty"} 1 9 10
23  
24 9 ▶ my %env = map split( '=', $_, 2 ),
Condition50%1/2
config("RESOURCE_ATTRIBUTES") // ""
l!l
09
MC/DC0%0/1
config("RESOURCE_ATTRIBUTES") // ""
config("RESOURCE_ATTRIBUTES")
Truth table50%1/2
A
A= config("RESOURCE_ATTRIBUTES")
Aresult
11
00
25 split ',', config('RESOURCE_ATTRIBUTES') // '';
26  
27 9 for ( keys %env ) {
28 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($env{$_} =~ /([^ \x{21} \x{23}-\x{2B} \x{2D}-\x{3A} \x{3C}-\x{5B} \x{5D}-\x{7E} ])/xx) 0 0 0
29 # baggage-octet, as per https://w3c.github.io/baggage/#definition
30 # ! # .. + - .. : < .. [ ] .. ~
31 $env{$_} =~ /([^ \x{21} \x{23}-\x{2B} \x{2D}-\x{3A} \x{3C}-\x{5B} \x{5D}-\x{7E} ])/xx
32 ) {
33 0 $logger->warn(
34 'Ignoring invalid resource attribute value in environment: must be percent-encoded',
35 { key => $_ },
36 );
37  
38 0 delete $env{$_};
39 }
40 }
41  
42 # Special-cased because of precedence rules
43 9 my $service_name = delete $env{'service.name'};
44 9 ▶ $service_name = config('SERVICE_NAME') // $service_name;
Condition33%1/3
config("SERVICE_NAME") // $service_name
l!l&&r!l&&!r
009
MC/DC0%0/2
config("SERVICE_NAME") // $service_name
config("SERVICE_NAME") $service_name
Truth table33%1/3
A // B
A= config("SERVICE_NAME")B= $service_name
ABresult
1X1
011
000
45  
46 $args{attributes} = {
47 'telemetry.sdk.name' => 'opentelemetry',
48 'telemetry.sdk.language' => 'perl',
49 'telemetry.sdk.version' => $OpenTelemetry::SDK::VERSION,
50 'process.pid' => $$,
51 'process.command' => $0,
52 'process.executable.path' => $^X,
53 'process.command_args' => [ @ARGV ],
54 'process.executable.name' => basename($^X),
55 'process.runtime.name' => 'perl',
56 'process.runtime.version' => "$^V",
57  
58 %env,
59  
60 9 ▶ %{ $args{attributes} // {} },
Condition50%1/2
$args{"attributes"} // {}
l!l
09
MC/DC0%0/1
$args{"attributes"} // {}
$args{"attributes"}
Truth table50%1/2
A
A= $args{"attributes"}
Aresult
11
00
61 };
62  
63 9 ▶ $args{attributes}{'service.name'} //= $service_name if $service_name;
Branch: 1 branch
BranchTrueFalseTotal
if $service_name 0 9 9
Condition0%0/3
$args{"attributes"}{"service.name"} //= $service_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"attributes"}{"service.name"} //= $service_name
$args{"attributes"}{"service.name"} $service_name
Truth table0%0/3
A //= B
A= $args{"attributes"}{"service.name"}B= $service_name
ABresult
1X1
011
000
64  
65 9 %args;
66 }
67  
68 0 ▶ method merge ( $new ) {
Subroutine merge: not called CC=6 SCAR=37.4
Pod documented
69 0 ▶ return $self unless isa_OpenTelemetry_SDK_Resource $new;
Branch: 1 branch
BranchTrueFalseTotal
unless isa_OpenTelemetry_SDK_Resource($new) 0 0 0
70  
71 0 my $ours = $self->schema_url;
72 0 my $theirs = $new->schema_url;
73  
74 0 ▶ if ( $ours && $theirs && $ours ne $theirs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ours and $theirs and $ours ne $theirs) 0 0 0
Condition0%0/6
$ours and $theirs and $ours ne $theirs
!ll&&!rl&&r
000
$ours and $theirs
!ll&&!rl&&r
000
MC/DC0%0/3
$ours and $theirs and $ours ne $theirs
$ours $theirs $ours ne $theirs
Truth table0%0/4
A and B and C
A= $oursB= $theirsC= $ours ne $theirs
ABCresult
0XX0
10X0
1100
1111
75 0 $logger->warn(
76 'Incompatible resource schema URLs when merging resources. Ignoring new one',
77 { old => $ours, new => $theirs },
78 );
79 0 $theirs = '';
80 }
81  
82 ( ref $self )->new(
83 0 ▶ attributes => { %{ $self->attributes }, %{ $new->attributes } },
Condition0%0/3
$theirs || $ours
l!l&&r!l&&!r
000
MC/DC0%0/2
$theirs || $ours
$theirs $ours
Truth table0%0/3
A || B
A= $theirsB= $ours
ABresult
1X1
011
000
84 schema_url => $theirs || $ours,
85 );
86 4 }
87 4 }
↑ Summary SDK/Trace/Sampler/ParentBased.pm »