Return empty objects when no spans are passed in OTLP/GRPC exporter implementation (#412)
* Return empty object if no spans are passed for OTLPGrpc * Return empty object if no spans are passed for OtlpHttp * Remove trailing whitespace * Remove extra whitespace
This commit is contained in:
parent
500ff88cdb
commit
1cfd72accf
|
|
@ -176,11 +176,12 @@ class SpanConverter
|
|||
|
||||
public function as_otlp_resource_span(iterable $spans): ResourceSpans
|
||||
{
|
||||
// TODO: Should return an empty ResourceSpans when $spans is empty
|
||||
// At the minute it returns an semi populated ResourceSpan
|
||||
$isSpansEmpty = true; //Waiting for the loop to prove otherwise
|
||||
|
||||
$ils = $convertedSpans = [];
|
||||
foreach ($spans as $span) {
|
||||
$isSpansEmpty = false;
|
||||
|
||||
/** @var \OpenTelemetry\Sdk\InstrumentationLibrary $il */
|
||||
$il = $span->getInstrumentationLibrary();
|
||||
$ilKey = sprintf('%s@%s', $il->getName(), $il->getVersion()??'');
|
||||
|
|
@ -191,6 +192,10 @@ class SpanConverter
|
|||
$convertedSpans[$ilKey][] = $this->as_otlp_span($span);
|
||||
}
|
||||
|
||||
if ($isSpansEmpty == true) {
|
||||
return new Proto\Trace\V1\ResourceSpans();
|
||||
}
|
||||
|
||||
$ilSpans = [];
|
||||
foreach ($ils as $ilKey => $il) {
|
||||
$ilSpans[] = new InstrumentationLibrarySpans([
|
||||
|
|
|
|||
|
|
@ -174,11 +174,12 @@ class SpanConverter
|
|||
|
||||
public function as_otlp_resource_span(iterable $spans): ResourceSpans
|
||||
{
|
||||
// TODO: Should return an empty ResourceSpans when $spans is empty
|
||||
// At the minute it returns an semi populated ResourceSpan
|
||||
$isSpansEmpty = true; //Waiting for the loop to prove otherwise
|
||||
|
||||
$ils = $convertedSpans = [];
|
||||
foreach ($spans as $span) {
|
||||
$isSpansEmpty = false;
|
||||
|
||||
/** @var \OpenTelemetry\Sdk\InstrumentationLibrary $il */
|
||||
$il = $span->getInstrumentationLibrary();
|
||||
$ilKey = sprintf('%s@%s', $il->getName(), $il->getVersion()??'');
|
||||
|
|
@ -189,6 +190,10 @@ class SpanConverter
|
|||
$convertedSpans[$ilKey][] = $this->as_otlp_span($span);
|
||||
}
|
||||
|
||||
if ($isSpansEmpty == true) {
|
||||
return new Proto\Trace\V1\ResourceSpans();
|
||||
}
|
||||
|
||||
$ilSpans = [];
|
||||
foreach ($ils as $ilKey => $il) {
|
||||
$ilSpans[] = new InstrumentationLibrarySpans([
|
||||
|
|
|
|||
|
|
@ -264,4 +264,13 @@ class OTLPGrpcSpanConverterTest extends TestCase
|
|||
|
||||
$this->assertEquals($expected, $otlpspan);
|
||||
}
|
||||
|
||||
public function testOtlpNoSpans()
|
||||
{
|
||||
$spans = [];
|
||||
|
||||
$otlpspan = (new SpanConverter())->as_otlp_resource_span($spans);
|
||||
|
||||
$this->assertEquals(new ResourceSpans(), $otlpspan);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,4 +252,13 @@ class OTLPHttpSpanConverterTest extends TestCase
|
|||
|
||||
$this->assertEquals($expected, $otlpspan);
|
||||
}
|
||||
|
||||
public function testOtlpNoSpans()
|
||||
{
|
||||
$spans = [];
|
||||
|
||||
$otlpspan = (new SpanConverter())->as_otlp_resource_span($spans);
|
||||
|
||||
$this->assertEquals(new ResourceSpans(), $otlpspan);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue