| 1 | 4 | ▶ | 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 | 4 | our $VERSION = '0.101'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | class OpenTelemetry::SDK::Logs::LoggerProvider | ||||||||||||||||||||
| 9 | :isa(OpenTelemetry::Logs::LoggerProvider) | ||||||||||||||||||||
| 10 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | ▶ | use Mutex; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 4 | ▶ | use OpenTelemetry::Common qw( timeout_timestamp maybe_timeout ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 4 | ▶ | use OpenTelemetry::Constants -export; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 4 | ▶ | use OpenTelemetry::SDK::InstrumentationScope; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 4 | ▶ | use OpenTelemetry::SDK::Logs::Logger; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 4 | ▶ | use OpenTelemetry::SDK::Logs::LogRecord; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 4 | ▶ | use OpenTelemetry::SDK::Resource; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 4 | ▶ | use OpenTelemetry::Trace; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 4 | ▶ | use Time::HiRes 'time'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | field $resource :param //= OpenTelemetry::SDK::Resource->new; | ||||||||||||||||||||
| 23 | 4 | field $stopped = 0; | |||||||||||||||||||
| 24 | 4 | field %registry; | |||||||||||||||||||
| 25 | 4 | field @processors; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | field $lock //= Mutex->new; | ||||||||||||||||||||
| 28 | 4 | field $registry_lock //= Mutex->new; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 4 | 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 | 4 | } | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ▶ | method logger (%args) { | ||||||||||||||||||
|
Subroutine
logger: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 57 | 4 | my %defaults; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 4 | $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 | 4 | ▶ | $args{name} || do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 2 | ( $args{name} ) = caller; | |||||||||||||||||||
| 65 | 2 | $args{version} = $args{name}->VERSION; | |||||||||||||||||||
| 66 | }; | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | OpenTelemetry::SDK::InstrumentationScope | ||||||||||||||||||||
| 69 | 4 | ->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 | 4 | ▶ | ), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | ) | ||||||||||||||||||||
| 78 | : $resource; | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 4 | ▶ | $registry_lock->enter( sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 81 | my $key | ||||||||||||||||||||
| 82 | = $defaults{instrumentation_scope}->to_string | ||||||||||||||||||||
| 83 | . '-' | ||||||||||||||||||||
| 84 | 4 | . $defaults{resource}->schema_url; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | $registry{$key} //= OpenTelemetry::SDK::Logs::Logger->new( | ||||||||||||||||||||
| 87 | 2 | ▶ | callback => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 88 | 2 | $self->$create_log_record( @_, %defaults ); | |||||||||||||||||||
| 89 | }, | ||||||||||||||||||||
| 90 | 4 | ▶ | ); | ||||||||||||||||||
|
Condition66%2/3
$registry{$key} //= "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub {
$self->$create_log_record(@_, %defaults);
}
)
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 table66%2/3
A //= B
A= $registry{$key}B= "OpenTelemetry::SDK::Logs::Logger"->new("callback", sub {
$self->$create_log_record(@_, %defaults);
}
)
| |||||||||||||||||||||
| 91 | 4 | }); | |||||||||||||||||||
| 92 | 4 | } | |||||||||||||||||||
| 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 | 4 | } | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | ▶ | async method shutdown ( $timeout = undef ) { | ||||||||||||||||||
|
Subroutine
shutdown: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 115 | 2 | ▶ | return EXPORT_RESULT_SUCCESS if $stopped; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | $lock->enter( | ||||||||||||||||||||
| 118 | 1 | ▶ | sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 119 | 1 | $stopped = 1; | |||||||||||||||||||
| 120 | 1 | $self->$atomic_call_on_processors( shutdown => $timeout ); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | 1 | ); | |||||||||||||||||||
| 123 | 4 | } | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 2 | ▶ | async method force_flush ( $timeout = undef ) { | ||||||||||||||||||
|
Subroutine
force_flush: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 126 | 2 | ▶ | return EXPORT_RESULT_SUCCESS if $stopped; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | $lock->enter( | ||||||||||||||||||||
| 129 | 2 | ▶ | sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 130 | 2 | $self->$atomic_call_on_processors( 'force_flush', $timeout ); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | 2 | ); | |||||||||||||||||||
| 133 | 4 | } | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 8 | ▶ | method add_log_record_processor ($processor) { | ||||||||||||||||||
|
Subroutine
add_log_record_processor: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 136 | 8 | ▶ | if ( $stopped ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | 1 | $logger->warn( | |||||||||||||||||||
| 138 | 'Attempted to add a log record processor to a LoggerProvider after shutdown' | ||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||
| 140 | 1 | return $self; | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 7 | my $candidate = ref $processor; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 7 | ▶ | 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
| |||||||||||||||||||||
| 146 | unless $processor->DOES('OpenTelemetry::Logs::LogRecord::Processor'); | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 6 | 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 | 6 | ▶ | if $seen{$candidate}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | $lock->enter( | ||||||||||||||||||||
| 154 | 5 | ▶ | sub { push @processors, $processor } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 155 | 5 | ); | |||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 5 | $self; | |||||||||||||||||||
| 158 | 4 | } | |||||||||||||||||||
| 159 | 4 | } | |||||||||||||||||||