SDK/Resource.pm

filter: Statementstmt 100% 49 / 49 Branchbran 90.0% 9 / 10 Conditioncond 78.9% 15 / 19 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 9 / 9 Podpod 50.0% 2 / 4 totaltotal 87.2% 89 / 102 CC 14 SCAR 17.3
CC
14
Cov
94%
BUILDARGS
9.0
merge
6.1
BEGIN
1.0
CRAP 5.7
« SDK/Trace/TracerProvider.pm ↑ Summary Processor/Batch.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.100';
6  
7 1 ▶class OpenTelemetry::SDK::Resource :does(OpenTelemetry::Attributes) {
Subroutine BEGIN: called CC=1 SCAR=0.0
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 22 field $schema_url :param :reader //= '';
18  
19 4 ▶ 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 27 ▶ sub BUILDARGS ( $class, %args ) {
Subroutine BUILDARGS: called CC=9 SCAR=22.0
Pod undocumented
22 27 ▶ return %args if delete $args{empty};
Branch: 1 branch
BranchTrueFalseTotal
if delete $args{"empty"} 4 23 27
23  
24 23 ▶ my %env = map split( '=', $_, 2 ),
Condition100%2/2
config("RESOURCE_ATTRIBUTES") // ""
l!l
815
MC/DC100%1/1
config("RESOURCE_ATTRIBUTES") // ""
config("RESOURCE_ATTRIBUTES")
Truth table100%2/2
A
A= config("RESOURCE_ATTRIBUTES")
Aresult
11
00
25 split ',', config('RESOURCE_ATTRIBUTES') // '';
26  
27 23 for ( keys %env ) {
28 12 ▶ 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) 6 6 12
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 6 $logger->warn(
34 'Ignoring invalid resource attribute value in environment: must be percent-encoded',
35 { key => $_ },
36 );
37  
38 6 delete $env{$_};
39 }
40 }
41  
42 # Special-cased because of precedence rules
43 23 my $service_name = delete $env{'service.name'};
44 23 ▶ $service_name = config('SERVICE_NAME') // $service_name;
Condition66%2/3
config("SERVICE_NAME") // $service_name
l!l&&r!l&&!r
2021
MC/DC50%1/2
config("SERVICE_NAME") // $service_name
config("SERVICE_NAME") $service_name
Truth table66%2/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 23 ▶ %{ $args{attributes} // {} },
Condition100%2/2
$args{"attributes"} // {}
l!l
914
MC/DC100%1/1
$args{"attributes"} // {}
$args{"attributes"}
Truth table100%2/2
A
A= $args{"attributes"}
Aresult
11
00
61 };
62  
63 23 ▶ $args{attributes}{'service.name'} //= $service_name if $service_name;
Branch: 1 branch
BranchTrueFalseTotal
if $service_name 2 21 23
Condition66%2/3
$args{"attributes"}{"service.name"} //= $service_name
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"attributes"}{"service.name"} //= $service_name
$args{"attributes"}{"service.name"} $service_name
Truth table66%2/3
A //= B
A= $args{"attributes"}{"service.name"}B= $service_name
ABresult
1X1
011
000
64  
65 23 %args;
66 }
67  
68 4 ▶ method merge ( $new ) {
Subroutine merge: called CC=6 SCAR=18.0
Pod documented
69 4 ▶ return $self unless isa_OpenTelemetry_SDK_Resource $new;
Branch: 1 branch
BranchTrueFalseTotal
unless isa_OpenTelemetry_SDK_Resource($new) 0 4 4
70  
71 4 my $ours = $self->schema_url;
72 4 my $theirs = $new->schema_url;
73  
74 4 ▶ if ( $ours && $theirs && $ours ne $theirs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ours and $theirs and $ours ne $theirs) 2 2 4
Condition83%5/6
$ours and $theirs and $ours ne $theirs
!ll&&!rl&&r
202
$ours and $theirs
!ll&&!rl&&r
112
MC/DC66%2/3
$ours and $theirs and $ours ne $theirs
$ours $theirs $ours ne $theirs
Truth table75%3/4
A and B and C
A= $oursB= $theirsC= $ours ne $theirs
ABCresult
0XX0
10X0
1100
1111
75 2 $logger->warn(
76 'Incompatible resource schema URLs when merging resources. Ignoring new one',
77 { old => $ours, new => $theirs },
78 );
79 2 $theirs = '';
80 }
81  
82 ( ref $self )->new(
83 4 ▶ attributes => { %{ $self->attributes }, %{ $new->attributes } },
Condition66%2/3
$theirs || $ours
l!l&&r!l&&!r
130
MC/DC0%0/2
$theirs || $ours
$theirs $ours
Truth table66%2/3
A || B
A= $theirsB= $ours
ABresult
1X1
011
000
84 schema_url => $theirs || $ours,
85 );
86 4 }
87 4 }
« SDK/Trace/TracerProvider.pm ↑ Summary Processor/Batch.pm »