From a6925d3ab5a43f374965cd784936882b40f9aa57 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 16 Jun 2017 11:36:30 -0700 Subject: [PATCH] Skip creating the labels info until there are labels. Revert extension name change in test --- src/Trace/TraceSpan.php | 6 +++++- tests/unit/Trace/TraceSpanTest.php | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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();