Skip to content

Commit

Permalink
Drop SDK dependency
Browse files Browse the repository at this point in the history
If the OTLP exporter is to be the default used by the SDK, then it doesn't
sit right that the exporter would depend on the SDK. This commit makes it
so that the exporter doesn't directly depend on the SDK to function, which
means that the SDK can then recommend the exporter as an optional dependency
without getting into a dependency cycle.

This wasn't o difficult since the only place we were still using the SDK
directly was in the test suite. It would still be a good idea to have an
optional test that ensured the exporter worked with the real SDK classes,
but for now it's enough to break the hard dependency.
  • Loading branch information
jjatria committed Nov 6, 2023
1 parent e90ccdb commit a3c6cb6
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 152 deletions.
1 change: 0 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"JSON::MaybeXS" : "0",
"Metrics::Any" : "0",
"Object::Pad" : "0",
"OpenTelemetry::SDK" : "0",
"Path::Tiny" : "0",
"perl" : "v5.20.0"
}
Expand Down
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ my %WriteMakefileArgs = (
"JSON::MaybeXS" => 0,
"Metrics::Any" => 0,
"Object::Pad" => 0,
"OpenTelemetry::SDK" => 0,
"Path::Tiny" => 0
},
"TEST_REQUIRES" => {
Expand All @@ -51,7 +50,6 @@ my %FallbackPrereqs = (
"JSON::MaybeXS" => 0,
"Metrics::Any" => 0,
"Object::Pad" => 0,
"OpenTelemetry::SDK" => 0,
"Path::Tiny" => 0,
"Test2::V0" => 0,
"Test::More" => 0
Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ requires 'File::Share';
requires 'JSON::MaybeXS';
requires 'Metrics::Any';
requires 'Object::Pad';
requires 'OpenTelemetry::SDK';
requires 'Path::Tiny';

recommends 'Compress::Zlib';
Expand Down
93 changes: 43 additions & 50 deletions t/OpenTelemetry/Exporter/OTLP.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,58 @@
use Log::Any::Adapter 'Stderr';
use Test2::V0 -target => 'OpenTelemetry::Exporter::OTLP';

use experimental 'signatures';

use HTTP::Tiny;
use OpenTelemetry::Constants -trace_export, -span_kind, -span_status;
use OpenTelemetry::Constants
'INVALID_SPAN_ID',
-trace_export,
-span_kind,
-span_status;
use OpenTelemetry::Trace::SpanContext;
use OpenTelemetry::SDK::Trace::Span::Readable;
use OpenTelemetry::SDK::Resource;
use OpenTelemetry::SDK::InstrumentationScope;
use OpenTelemetry::Trace::Span::Status;

my $guard = mock 'HTTP::Tiny' => override => [
my $http_mock = mock 'HTTP::Tiny' => override => [
request => sub { +{ success => 1 } },
];

my $a_scope = OpenTelemetry::SDK::InstrumentationScope->new( name => 'A' );
my $b_scope = OpenTelemetry::SDK::InstrumentationScope->new( name => 'B' );

my $a_resource = OpenTelemetry::SDK::Resource->new( attributes => { name => 'A' } );
my $b_resource = OpenTelemetry::SDK::Resource->new( attributes => { name => 'B' } );
my $span_mock = mock 'Local::Span' => add => [
attributes => sub { {} },
dropped_attributes => 0,
dropped_events => 0,
dropped_links => 0,
end_timestamp => 100,
events => sub { },
kind => sub { SPAN_KIND_INTERNAL },
links => sub { },
name => sub { shift->{name} //= 'X' },
parent_span_id => sub { INVALID_SPAN_ID },
span_id => sub { shift->{context}->span_id },
start_timestamp => 0,
status => sub { OpenTelemetry::Trace::Span::Status->ok },
trace_flags => sub { shift->{context}->trace_flags },
trace_id => sub { shift->{context}->trace_id },
trace_state => sub { shift->{context}->trace_state },
new => sub ( $class, %data ) {
$data{context} //= OpenTelemetry::Trace::SpanContext->new;
bless \%data, $class;
},
instrumentation_scope => sub {
shift->{scope} //= mock {} => add => [ name => 'X' ];
},
resource => sub {
shift->{resource} //= mock {} => add => [
attributes => sub { +{} },
dropped_attributes => 0,
];
},
];

is CLASS->new->export([
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $a_scope,
kind => SPAN_KIND_INTERNAL,
name => 'A-A',
resource => $a_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $a_scope,
kind => SPAN_KIND_INTERNAL,
name => 'A-B',
resource => $b_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $b_scope,
kind => SPAN_KIND_INTERNAL,
name => 'B-A',
resource => $a_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $b_scope,
kind => SPAN_KIND_INTERNAL,
name => 'B-B',
resource => $b_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
),
Local::Span->new,
Local::Span->new,
Local::Span->new,
Local::Span->new,
]), TRACE_EXPORT_SUCCESS;

done_testing;
111 changes: 67 additions & 44 deletions t/OpenTelemetry/Exporter/OTLP/Encoder/JSON.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,83 @@

use Test2::V0 -target => 'OpenTelemetry::Exporter::OTLP::Encoder::JSON';

use experimental 'signatures';

use JSON::MaybeXS;
use OpenTelemetry::Constants -trace_export, -span_kind, -span_status;
use OpenTelemetry::Constants
'INVALID_SPAN_ID',
-trace_export,
-span_kind,
-span_status;
use OpenTelemetry::Trace::SpanContext;
use OpenTelemetry::SDK::Trace::Span::Readable;
use OpenTelemetry::SDK::Resource;
use OpenTelemetry::SDK::InstrumentationScope;
use OpenTelemetry::Trace::Span::Status;

my $a_scope = OpenTelemetry::SDK::InstrumentationScope->new( name => 'A' );
my $b_scope = OpenTelemetry::SDK::InstrumentationScope->new( name => 'B' );
my $scope_mock = mock 'Local::Scope' => add => [
new => sub ( $class, %data ) { bless \%data, $class },
dropped_attributes => 0,
version => '',
name => sub { shift->{name} //= 'SCOPE' },
attributes => sub { +{} },
];

my $resource_mock = mock 'Local::Resource' => add => [
new => sub ( $class, %data ) { bless \%data, $class },
dropped_attributes => 0,
schema_url => '',
attributes => sub { shift->{attributes} //= {} },
];

my $a_scope = Local::Scope->new( name => 'A' );
my $b_scope = Local::Scope->new( name => 'B' );

my $a_resource = OpenTelemetry::SDK::Resource->new( attributes => { name => 'A' } );
my $b_resource = OpenTelemetry::SDK::Resource->new( attributes => { name => 'B' } );
my $a_resource = Local::Resource->new( attributes => { name => 'A' } );
my $b_resource = Local::Resource->new( attributes => { name => 'B' } );

my $span_mock = mock 'Local::Span' => add => [
new => sub ( $class, %data ) {
$data{context} //= OpenTelemetry::Trace::SpanContext->new;
bless \%data, $class;
},
attributes => sub { {} },
dropped_attributes => 0,
dropped_events => 0,
dropped_links => 0,
end_timestamp => 100,
events => sub { },
kind => sub { SPAN_KIND_INTERNAL },
links => sub { },
name => sub { shift->{name} //= 'X' },
parent_span_id => sub { INVALID_SPAN_ID },
span_id => sub { shift->{context}->span_id },
start_timestamp => 0,
status => sub { OpenTelemetry::Trace::Span::Status->ok },
trace_flags => sub { shift->{context}->trace_flags },
trace_id => sub { shift->{context}->trace_id },
trace_state => sub { shift->{context}->trace_state },
instrumentation_scope => sub { shift->{scope} //= Local::Scope->new },
resource => sub { shift->{resource} //= Local::Resource->new },
];

is decode_json(CLASS->new->encode([
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $a_scope,
kind => SPAN_KIND_INTERNAL,
name => 'A-A',
resource => $a_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
Local::Span->new(
scope => $a_scope,
name => 'A-A',
resource => $a_resource,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $a_scope,
kind => SPAN_KIND_INTERNAL,
name => 'A-B',
resource => $b_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
Local::Span->new(
scope => $a_scope,
name => 'A-B',
resource => $b_resource,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $b_scope,
kind => SPAN_KIND_INTERNAL,
name => 'B-A',
resource => $a_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
Local::Span->new(
scope => $b_scope,
name => 'B-A',
resource => $a_resource,
),
OpenTelemetry::SDK::Trace::Span::Readable->new(
context => OpenTelemetry::Trace::SpanContext->new,
end_timestamp => 100,
instrumentation_scope => $b_scope,
kind => SPAN_KIND_INTERNAL,
name => 'B-B',
resource => $b_resource,
start_timestamp => 0,
status => OpenTelemetry::Trace::Span::Status->ok,
Local::Span->new(
scope => $b_scope,
name => 'B-B',
resource => $b_resource,
),
])), {
resourceSpans => array {
Expand Down
Loading

0 comments on commit a3c6cb6

Please sign in to comment.