SDK/Logs/LoggerProvider.pm

filter: Statementstmt 52.0% 51 / 98 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 12 / 21 Podpod 100% 4 / 4 totaltotal 47.1% 67 / 142 CC 11 SCAR 19.6
CC
11
Cov
44%
add_log_record_processor
20.0
logger
12.0
shutdown
12.0
CRAP 7.1
« SDK/Resource.pm ↑ Summary SDK/Trace/Tracer.pm »
1 3 ▶use Object::Pad ':experimental(init_expr)';
Subroutine BEGIN: called CC=1 SCAR=0.0
2 # ABSTRACT: A LoggerProvider for the OpenTelemetry SDK
3  
4 package OpenTelemetry::SDK::Logs::LoggerProvider;
5  
6 3 our $VERSION = '0.102';
7  
8 class OpenTelemetry::SDK::Logs::LoggerProvider
9 :isa(OpenTelemetry::Logs::LoggerProvider)
10 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶ use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶ use Mutex;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶ use OpenTelemetry::Common qw( timeout_timestamp maybe_timeout );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶ use OpenTelemetry::Constants -export;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶ use OpenTelemetry::SDK::InstrumentationScope;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶ use OpenTelemetry::SDK::Logs::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶ use OpenTelemetry::SDK::Logs::LogRecord;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶ use OpenTelemetry::SDK::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶ use OpenTelemetry::Trace;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶ use Time::HiRes 'time';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 field $resource :param //= OpenTelemetry::SDK::Resource->new;
23 3 field $stopped = 0;
24 3 field %registry;
25 3 field @processors;
26  
27 field $lock //= Mutex->new;
28 3 field $registry_lock //= Mutex->new;
29  
30 3 my $logger = OpenTelemetry::Common::internal_logger;
31  
32 method $create_log_record (%args) {
33 return if $stopped;
34  
35 my %log = %args{qw(
36 attributes
37 body
38 observed_timestamp
39 resource
40 instrumentation_scope
41 severity_number
42 severity_text
43 timestamp
44 context
45 )};
46  
47 $log{observed_timestamp} //= time;
48  
49 my $record = OpenTelemetry::SDK::Logs::LogRecord->new(%log);
50  
51 $_->on_emit($record) for @processors;
52  
53 $record;
54 3 }
55  
56 0 ▶ method logger (%args) {
Subroutine logger: not called CC=3 SCAR=24.8
Pod documented
57 0 my %defaults;
58  
59 0 $defaults{instrumentation_scope} = do {
60 # If no name is provided, we get it from the caller
61 # This has to override the version, since the version
62 # only makes sense for the name
63 0 ▶ $args{name} || do {
Branch: 1 branch
BranchTrueFalseTotal
$args{"name"} or do { ($args{"name"}) = caller; $args{"version"} = $args{"name"}->VERSION } 0 0 0
64 0 ( $args{name} ) = caller;
65 0 $args{version} = $args{name}->VERSION;
66 };
67  
68 OpenTelemetry::SDK::InstrumentationScope
69 0 ->new( %args{qw( name version attributes )} );
70 };
71  
72 $defaults{resource} = $args{schema_url}
73 ? $resource->merge(
74 OpenTelemetry::SDK::Resource->empty(
75 schema_url => $args{schema_url}
76 0 ▶ ),
Branch: 1 branch
BranchTrueFalseTotal
$args{'schema_url'} ? : 0 0 0
77 )
78 : $resource;
79  
80 0 ▶ $registry_lock->enter( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
81 my $key
82 = $defaults{instrumentation_scope}->to_string
83 . '-'
84 0 . $defaults{resource}->schema_url;
85  
86 $registry{$key} //= OpenTelemetry::SDK::Logs::Logger->new(
87 0 ▶ callback => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 $self->$create_log_record( @_, %defaults );
89 },
90 0 ▶ );
Condition0%0/3
$registry{$key} //= "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub { $self->$create_log_record(@_, %defaults); } )
l!l&&r!l&&!r
000
MC/DC0%0/2
$registry{$key} //= "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub { $self->$create_log_record(@_, %defaults); } )
$registry{$key} "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub { $self->$create_log_record(@_, %defaults); } )
Truth table0%0/3
A //= B
A= $registry{$key}B= "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub { $self->$create_log_record(@_, %defaults); } )
ABresult
1X1
011
000
91 0 });
92 3 }
93  
94 method $atomic_call_on_processors ( $method, $timeout ) {
95 my $start = timeout_timestamp;
96  
97 my $result = EXPORT_RESULT_SUCCESS;
98  
99 for my $processor ( @processors ) {
100 my $remaining = maybe_timeout $timeout, $start;
101  
102 if ( defined $remaining && $remaining == 0 ) {
103 $result = EXPORT_RESULT_TIMEOUT;
104 last;
105 }
106  
107 my $res = $processor->$method($remaining)->get;
108 $result = $res if $res > $result;
109 }
110  
111 return $result;
112 3 }
113  
114 0 ▶ async method shutdown ( $timeout = undef ) {
Subroutine shutdown: not called CC=3 SCAR=24.8
Pod documented
115 0 ▶ return EXPORT_RESULT_SUCCESS if $stopped;
Branch: 1 branch
BranchTrueFalseTotal
if $stopped 0 0 0
116  
117 $lock->enter(
118 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 0 $stopped = 1;
120 0 $self->$atomic_call_on_processors( shutdown => $timeout );
121 }
122 0 );
123 3 }
124  
125 0 ▶ async method force_flush ( $timeout = undef ) {
Subroutine force_flush: not called CC=3 SCAR=24.8
Pod documented
126 0 ▶ return EXPORT_RESULT_SUCCESS if $stopped;
Branch: 1 branch
BranchTrueFalseTotal
if $stopped 0 0 0
127  
128 $lock->enter(
129 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
130 0 $self->$atomic_call_on_processors( 'force_flush', $timeout );
131 }
132 0 );
133 3 }
134  
135 0 ▶ method add_log_record_processor ($processor) {
Subroutine add_log_record_processor: not called CC=4 SCAR=30.0
Pod documented
136 0 ▶ if ( $stopped ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stopped) 0 0 0
137 0 $logger->warn(
138 'Attempted to add a log record processor to a LoggerProvider after shutdown'
139 );
140 0 return $self;
141 }
142  
143 0 my $candidate = ref $processor;
144  
145 0 ▶ return $logger->warn("Attempted to add a $candidate object as a log record processor to a LoggerProvider, but it does not do the OpenTelemetry::Logs::LogRecord::Processor")
Branch: 1 branch
BranchTrueFalseTotal
unless $processor->DOES("OpenTelemetry::Logs::LogRecord::Processor") 0 0 0
146 unless $processor->DOES('OpenTelemetry::Logs::LogRecord::Processor');
147  
148 0 my %seen = map { ref, 1 } @processors;
149  
150 return $logger->warn("Attempted to add a $candidate log record processor to a LoggerProvider more than once")
151 0 ▶ if $seen{$candidate};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$candidate} 0 0 0
152  
153 $lock->enter(
154 0 ▶ sub { push @processors, $processor }
Subroutine __ANON__: not called CC=1 SCAR=6.9
155 0 );
156  
157 0 $self;
158 3 }
159 3 }
« SDK/Resource.pm ↑ Summary SDK/Trace/Tracer.pm »