diff --git a/src/Trace/TraceSpan.php b/src/Trace/TraceSpan.php index 664a5e882643..c9c5e27b5aa1 100644 --- a/src/Trace/TraceSpan.php +++ b/src/Trace/TraceSpan.php @@ -67,7 +67,7 @@ class TraceSpan implements \JsonSerializable public function __construct($options = []) { $this->info = $this->pluckArray( - ['spanId', 'kind', 'name', 'parentSpanId', 'labels'], + ['spanId', 'kind', 'name', 'parentSpanId'], $options ); @@ -78,6 +78,10 @@ public function __construct($options = []) $this->setEnd($options['endTime']); } + if (array_key_exists('labels', $options)) { + $this->addLabels($options['labels']); + } + $this->info += [ 'kind' => self::SPAN_KIND_UNSPECIFIED ]; diff --git a/tests/unit/Trace/TraceSpanTest.php b/tests/unit/Trace/TraceSpanTest.php index 349ecec99c11..35757c3556a3 100644 --- a/tests/unit/Trace/TraceSpanTest.php +++ b/tests/unit/Trace/TraceSpanTest.php @@ -67,6 +67,13 @@ public function testNoLabels() $this->assertArrayNotHasKey('labels', $info); } + public function testEmptyLabels() + { + $traceSpan = new TraceSpan(['labels' => []]); + $info = $traceSpan->info(); + $this->assertArrayNotHasKey('labels', $info); + } + public function testGeneratesDefaultSpanName() { $traceSpan = new TraceSpan();