| 1 | package OpenTelemetry; | ||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A Perl implementation of the OpenTelemetry standard | ||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use experimental qw( signatures ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 9 | our $VERSION = '0.040'; | |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Mutex; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use OpenTelemetry::Common; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use OpenTelemetry::Context; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use OpenTelemetry::Propagator::None; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use OpenTelemetry::Trace::TracerProvider; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use OpenTelemetry::Logs::LoggerProvider; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use OpenTelemetry::X; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use Scalar::Util 'refaddr'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use Ref::Util 'is_coderef'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use Sentinel; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use isa qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | OpenTelemetry::Logs::LoggerProvider | ||||||||||||||||||||||||||||||||||||||
| 23 | OpenTelemetry::Trace::TracerProvider | ||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ); | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use Log::Any; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | use Exporter::Shiny qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | otel_config | ||||||||||||||||||||||||||||||||||||||
| 30 | otel_context_with_span | ||||||||||||||||||||||||||||||||||||||
| 31 | otel_current_context | ||||||||||||||||||||||||||||||||||||||
| 32 | otel_error_handler | ||||||||||||||||||||||||||||||||||||||
| 33 | otel_handle_error | ||||||||||||||||||||||||||||||||||||||
| 34 | otel_logger | ||||||||||||||||||||||||||||||||||||||
| 35 | otel_logger_provider | ||||||||||||||||||||||||||||||||||||||
| 36 | otel_propagator | ||||||||||||||||||||||||||||||||||||||
| 37 | otel_span_from_context | ||||||||||||||||||||||||||||||||||||||
| 38 | otel_tracer_provider | ||||||||||||||||||||||||||||||||||||||
| 39 | otel_untraced_context | ||||||||||||||||||||||||||||||||||||||
| 40 | 9 | ); | |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 9 | my $logger = OpenTelemetry::Common::internal_logger; | |||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub logger { $logger } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
logger: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub _generate_otel_logger { \&logger } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_logger: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||
| 47 | 9 | my $lock = Mutex->new; | |||||||||||||||||||||||||||||||||||||
| 48 | 9 | my $instance = OpenTelemetry::Trace::TracerProvider->new; | |||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | my $set = sub ( $new ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||
| 51 | 6 | ▶ | die OpenTelemetry::X->create( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $new || 'a plain scalar'
MC/DC0%0/1
ref $new || 'a plain scalar'
ref $new
Truth table50%1/2
A
A= ref $new
| |||||||||||||||||||||||||||||||||||||||
| 52 | Invalid => 'Global tracer provider must be a subclass of OpenTelemetry::Trace::TracerProvider, got instead ' . ( ref $new || 'a plain scalar' ), | ||||||||||||||||||||||||||||||||||||||
| 53 | ) unless isa_OpenTelemetry_Trace_TracerProvider $new; | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | $lock->enter( sub { $instance = $new }); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 56 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | sub _generate_otel_tracer_provider { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_tracer_provider: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | my $x = sub :lvalue { sentinel get => sub { $instance }, set => $set }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | sub tracer_provider :lvalue { sentinel get => sub { $instance }, set => $set } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
tracer_provider: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | # FIXME: The functions in this block mean that in all likelihood | ||||||||||||||||||||||||||||||||||||||
| 66 | # OpenTelemetry->logger will have to go away. It no longer fits, | ||||||||||||||||||||||||||||||||||||||
| 67 | # since we gain the concept of a logger, which is different from | ||||||||||||||||||||||||||||||||||||||
| 68 | # the logger we used to return (which is just a Log::Any logger). | ||||||||||||||||||||||||||||||||||||||
| 69 | # This is not such a big problem: it just means that users who | ||||||||||||||||||||||||||||||||||||||
| 70 | # want to use the same logger as the rest of the OpenTelemetry | ||||||||||||||||||||||||||||||||||||||
| 71 | # implementation need to do | ||||||||||||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||||||||||||
| 73 | # my $log = Log::Any->get_logger( category => 'OpenTelemetry' ); | ||||||||||||||||||||||||||||||||||||||
| 74 | # | ||||||||||||||||||||||||||||||||||||||
| 75 | # but you can argue that that's not so onerous, and if it is, that | ||||||||||||||||||||||||||||||||||||||
| 76 | # logging on that given category rather than the default one is | ||||||||||||||||||||||||||||||||||||||
| 77 | # pointless. | ||||||||||||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||||||||||
| 79 | 9 | my $lock = Mutex->new; | |||||||||||||||||||||||||||||||||||||
| 80 | 9 | my $instance = OpenTelemetry::Logs::LoggerProvider->new; | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my $set = sub ( $new ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | die OpenTelemetry::X->create( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $new || 'a plain scalar'
MC/DC0%0/1
ref $new || 'a plain scalar'
ref $new
Truth table0%0/2
A
A= ref $new
| |||||||||||||||||||||||||||||||||||||||
| 84 | Invalid => 'Global logger provider must be a subclass of OpenTelemetry::Logs::LoggerProvider, got instead ' . ( ref $new || 'a plain scalar' ), | ||||||||||||||||||||||||||||||||||||||
| 85 | ) unless isa_OpenTelemetry_Logs_LoggerProvider $new; | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | $lock->enter( sub { $instance = $new }); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 88 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub _generate_otel_logger_provider { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_logger_provider: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | my $x = sub :lvalue { sentinel get => sub { $instance }, set => $set }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub logger_provider :lvalue { sentinel get => sub { $instance }, set => $set } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
logger_provider: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||
| 98 | 9 | my $lock = Mutex->new; | |||||||||||||||||||||||||||||||||||||
| 99 | 9 | my $instance = OpenTelemetry::Propagator::None->new; | |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 8 | ▶ | my $set = sub ( $new ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 102 | 8 | ▶ | die OpenTelemetry::X->create( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$new and $new->DOES("OpenTelemetry::Propagator")
ref $new || 'a plain scalar'
MC/DC0%0/2
$new and $new->DOES("OpenTelemetry::Propagator")
$new
$new->DOES("OpenTelemetry::Propagator")
MC/DC0%0/1
ref $new || 'a plain scalar'
ref $new
Truth table33%1/3
A and B
A= $newB= $new->DOES("OpenTelemetry::Propagator")
Truth table0%0/2
A
A= ref $new
| |||||||||||||||||||||||||||||||||||||||
| 103 | Invalid => 'Global propagator must implement the OpenTelemetry::Propagator role, got instead ' . ( ref $new || 'a plain scalar' ), | ||||||||||||||||||||||||||||||||||||||
| 104 | ) unless $new && $new->DOES('OpenTelemetry::Propagator'); | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | 8 | ▶ | $lock->enter( sub { $instance = $new }); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 107 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | sub _generate_otel_propagator { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_propagator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | my $x = sub :lvalue { sentinel get => sub { $instance }, set => $set }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 34 | ▶ | sub propagator :lvalue { sentinel get => sub { $instance }, set => $set } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
propagator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | 9 | ▶ | sub _generate_otel_untraced_context { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_untraced_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | my $sub = sub :lvalue { OpenTelemetry::Trace->untraced_context }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | sub _generate_otel_current_context { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_current_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | my $sub = sub :lvalue { OpenTelemetry::Context->current }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | sub _generate_otel_context_with_span { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_context_with_span: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub { OpenTelemetry::Trace->context_with_span(@_) }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | sub _generate_otel_span_from_context { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_span_from_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 129 | 3 | ▶ | sub { OpenTelemetry::Trace->span_from_context(@_) }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | 3 | ▶ | sub _generate_otel_config { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 133 | 3 | \&OpenTelemetry::Common::config; | |||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||||||||||||
| 137 | 9 | my $lock = Mutex->new; | |||||||||||||||||||||||||||||||||||||
| 138 | 8 | ▶ | my $instance = sub (%args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 139 | my $error = join ' - ', grep defined, | ||||||||||||||||||||||||||||||||||||||
| 140 | 8 | @args{qw( message exception )}; | |||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | 8 | $logger->error( "OpenTelemetry error: $error", $args{details} ); | |||||||||||||||||||||||||||||||||||||
| 143 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | my $set = sub ( $new ) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | die OpenTelemetry::X->create( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $new || 'a plain scalar'
MC/DC0%0/1
ref $new || 'a plain scalar'
ref $new
Truth table50%1/2
A
A= ref $new
| |||||||||||||||||||||||||||||||||||||||
| 147 | Invalid => 'Global error handler must be a code reference, got instead ' . ( ref $new || 'a plain scalar' ), | ||||||||||||||||||||||||||||||||||||||
| 148 | ) unless is_coderef $new; | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | $lock->enter( sub { $instance = $new }); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 151 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | sub _generate_otel_error_handler { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_otel_error_handler: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | my $x = sub :lvalue { sentinel get => sub { $instance }, set => $set }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | sub error_handler :lvalue { sentinel get => sub { $instance }, set => $set } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
error_handler: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | sub _generate_otel_handle_error { sub { $instance->(@_); return } } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_generate_otel_handle_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 160 | 5 | ▶ | sub handle_error { shift; $instance->(@_); return } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 9 | 1; | |||||||||||||||||||||||||||||||||||||