Skip to content

Commit

Permalink
Use CPAN's isa to support 5.30
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatria committed Dec 19, 2024
1 parent f083c10 commit fb6f8c9
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

# All supported Perl versions except latest.
perl: [
'5.32', '5.34', '5.36',
'5.30', '5.32', '5.34', '5.36',
]

# Variants of the latest Perl.
Expand Down
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;


use v5.32.0;
use v5.30.0;
use Module::Build::Tiny 0.034;
Build_PL();

4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Revision history for OpenTelemetry-SDK
during initialisation. This will only affect the code executed
during import. Once the SDK has been loaded, it will never
intentionally raise an exception.
* Add 'isa' as a dependency and reduce the minimum supported Perl
version to 5.30. If you are running 5.30 please consider installing
Type::Tiny::XS which should improve the performance of these 'isa'
checks.

0.024 2024-08-02 15:28:11+01:00 Europe/London

Expand Down
7 changes: 4 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"configure" : {
"requires" : {
"Module::Build::Tiny" : "0.034",
"perl" : "v5.32.0"
"perl" : "v5.30.0"
}
},
"develop" : {
Expand All @@ -52,7 +52,8 @@
"Object::Pad" : "0.74",
"OpenTelemetry" : "0.010",
"bigfloat" : "0.65",
"perl" : "v5.32.0"
"isa" : "0",
"perl" : "v5.30.0"
}
},
"test" : {
Expand All @@ -67,7 +68,7 @@
"Syntax::Keyword::Dynamically" : "0",
"Test2::V0" : "0",
"Test::More" : "0",
"perl" : "v5.32.0"
"perl" : "v5.30.0"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requires 'isa'; # To support perls older than 5.32
requires 'Feature::Compat::Try';
requires 'Future::AsyncAwait', '0.38'; # Object::Pad compatibility
requires 'IO::Async::Loop';
Expand Down
2 changes: 2 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Release_Commit.commit_msg = Release v%V%t
Git::Tag.tag_message =

[MinimumPerl]
perl = v5.30.0

[Prereqs::FromCPANfile]

[Repository]
Expand Down
6 changes: 4 additions & 2 deletions lib/OpenTelemetry/SDK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ our $VERSION = '0.025';

use strict;
use warnings;
use experimental qw( isa signatures lexical_subs );
use experimental qw( signatures lexical_subs );
use feature 'state';

use Feature::Compat::Try;
Expand All @@ -16,6 +16,8 @@ use OpenTelemetry::Propagator::Composite;
use OpenTelemetry::SDK::Trace::TracerProvider;
use OpenTelemetry::X;

use isa 'OpenTelemetry::X';

my sub configure_propagators {
my $logger = Log::Any->get_logger( category => 'OpenTelemetry' );

Expand Down Expand Up @@ -122,7 +124,7 @@ sub import ( $class ) {
configure_span_processors();
}
catch ($e) {
die $e if $e isa OpenTelemetry::X;
die $e if isa_OpenTelemetry_X $e;
die OpenTelemetry::X->create(
Invalid => "Unexpected error initialising OpenTelemetry::SDK: $e",
);
Expand Down
6 changes: 3 additions & 3 deletions lib/OpenTelemetry/SDK/Resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package OpenTelemetry::SDK::Resource;
our $VERSION = '0.025';

class OpenTelemetry::SDK::Resource :does(OpenTelemetry::Attributes) {
use experimental 'isa';

use File::Basename 'basename';
use Log::Any;
use OpenTelemetry::Common 'config';

use isa 'OpenTelemetry::SDK::Resource';

my $logger = Log::Any->get_logger( category => 'OpenTelemetry' );

require OpenTelemetry::SDK; # For VERSION
Expand Down Expand Up @@ -67,7 +67,7 @@ class OpenTelemetry::SDK::Resource :does(OpenTelemetry::Attributes) {
}

method merge ( $new ) {
return $self unless $new isa OpenTelemetry::SDK::Resource;
return $self unless isa_OpenTelemetry_SDK_Resource $new;

my $ours = $self->schema_url;
my $theirs = $new->schema_url;
Expand Down
14 changes: 9 additions & 5 deletions lib/OpenTelemetry/SDK/Trace/Span.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class OpenTelemetry::SDK::Trace::Span
:isa(OpenTelemetry::Trace::Span)
:does(OpenTelemetry::Attributes)
{
use experimental 'isa';

use List::Util qw( any pairs );
use Log::Any;
use Ref::Util qw( is_arrayref is_hashref );
Expand All @@ -28,6 +26,12 @@ class OpenTelemetry::SDK::Trace::Span
use OpenTelemetry::Trace::Span::Status;
use OpenTelemetry::Trace;

use isa qw(
Exception::Base
Exception::Class::Base
OpenTelemetry::Trace::SpanContext
);

my $logger = Log::Any->get_logger( category => 'OpenTelemetry' );

field $dropped_events = 0;
Expand Down Expand Up @@ -55,7 +59,7 @@ class OpenTelemetry::SDK::Trace::Span
# Links with invalid span contexts are ignored
#
method $add_link ( $args ) {
return unless $args->{context} isa OpenTelemetry::Trace::SpanContext
return unless isa_OpenTelemetry_Trace_SpanContext($args->{context})
&& $args->{context}->valid;

if ( scalar @links >= $limits->link_count_limit ) {
Expand Down Expand Up @@ -162,7 +166,7 @@ class OpenTelemetry::SDK::Trace::Span
return $self unless $self->recording;

my ( $message, $stacktrace );
if ( $exception isa Exception::Class::Base ) {
if ( isa_Exception_Class_Base $exception ) {
$message = $exception->message;
$stacktrace = $exception->trace->as_string;
}
Expand All @@ -183,7 +187,7 @@ class OpenTelemetry::SDK::Trace::Span
( $message, $stacktrace ) = split /\n/, "$exception", 2;

$stacktrace //= $exception->get_caller_stacktrace
if $exception isa Exception::Base;
if isa_Exception_Base $exception;
}

$self->add_event(
Expand Down
6 changes: 2 additions & 4 deletions lib/OpenTelemetry/SDK/Trace/TracerProvider.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class OpenTelemetry::SDK::Trace::TracerProvider :isa(OpenTelemetry::Trace::Trace
use OpenTelemetry::SDK::Trace::Tracer;
use OpenTelemetry::Trace::SpanContext;

use experimental 'isa';

field $sampler :param = undef;
field $id_generator :param = 'OpenTelemetry::Trace';
field $span_limits :param //= OpenTelemetry::SDK::Trace::SpanLimits->new;
Expand Down Expand Up @@ -235,11 +233,11 @@ class OpenTelemetry::SDK::Trace::TracerProvider :isa(OpenTelemetry::Trace::Trace
->warn('Attempted to add an object that does not do the OpenTelemetry::Trace::Span::Processor role as a span processor to a TraceProvider')
unless $processor->DOES('OpenTelemetry::Trace::Span::Processor');

my %seen = map { ref, 1 } @processors;
my $candidate = ref $processor;

return OpenTelemetry->logger
->warn("Attempted to add a $candidate span processor to a TraceProvider more than once")
if any { $_ isa $candidate } @processors;
->warn("Attempted to add a $candidate span processor to a TraceProvider more than once") if $seen{$candidate};

push @processors, $processor;
});
Expand Down
26 changes: 22 additions & 4 deletions t/OpenTelemetry/SDK/Trace/TracerProvider.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
use Test2::V0 -target => 'OpenTelemetry::SDK::Trace::TracerProvider';
use Test2::Tools::OpenTelemetry;

use OpenTelemetry::SDK::InstrumentationScope;

my $provider = CLASS->new;

subtest Tracer => sub {
my $provider = CLASS->new;

no_messages {
is my $default = $provider->tracer, object {
prop isa => 'OpenTelemetry::SDK::Trace::Tracer';
Expand All @@ -22,4 +20,24 @@ subtest Tracer => sub {
};
};

subtest SpanProcessors => sub {
my $provider = CLASS->new;
my $processor = mock {} => add => [ DOES => 1 ];

no_messages {
ref_is $provider->add_span_processor($processor), $provider,
'Adding span processor chains';
};

is messages {
ref_is $provider->add_span_processor($processor), $provider,
'Adding span processor chains';
} => [
[
warning => 'OpenTelemetry',
match qr/^Attempted to add .* span processor .* more than once/,
],
] => 'Warned about repeated processor';
};

done_testing;

0 comments on commit fb6f8c9

Please sign in to comment.