Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a50a858

Browse files
committed
fix T_EXIT parse error on PHP < 7
PHP < 7 will treat Instana::exit() as if exit was T_EXIT instead of a method name causing any PHP < 7 to terminate with a parser error. Calling the method via `call_user_func` works around this. This commit also adds a method InstanaSpanType::exitType() for use in consumer code using PHP < 7.
1 parent f75612b commit a50a858

5 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/Instana/OpenTracing/InstanaSpan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function setTag($key, $value)
164164
break;
165165
case \OpenTracing\Tags\SPAN_KIND_RPC_CLIENT:
166166
case \OpenTracing\Tags\SPAN_KIND_MESSAGE_BUS_PRODUCER:
167-
$this->spanType = InstanaSpanType::exit();
167+
$this->spanType = call_user_func(__NAMESPACE__ . '\InstanaSpanType::exit');
168168
break;
169169
}
170170
break;

src/Instana/OpenTracing/InstanaSpanType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ public static function exit() {
5959
return self::$exit;
6060
}
6161

62+
/**
63+
* Workaround for PHP < 7 where exit() is parsed as T_EXIT
64+
*
65+
* @return InstanaSpanType
66+
* @deprecated Upgrade to PHP7 to use InstanaSpanType::exit()
67+
*/
68+
public static function exitType() {
69+
if (self::$exit === null) {
70+
self::$exit = new InstanaSpanType(2, 'exit');
71+
}
72+
return self::$exit;
73+
}
74+
6275
/**
6376
* @return InstanaSpanType
6477
*/

test/Instana/OpenTracing/InstanaHttpSpanFlusherTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ public function startingActiveSpans()
167167

168168
$child = \OpenTracing\GlobalTracer::get()->startActiveSpan('my_second_span');
169169
$child->getSpan()->setTag('bar', 2);
170+
$child->close();
170171

172+
$child = \OpenTracing\GlobalTracer::get()->startActiveSpan('my_third_span');
173+
$child->getSpan()->setTag('span.kind', 'client');
171174
$child->close();
175+
172176
$parent->close();
173177

174178
\OpenTracing\GlobalTracer::get()->flush();
@@ -193,6 +197,15 @@ public function startingActiveSpans()
193197
'duration' => $spanData[1]['duration'],
194198
'type' => 'LOCAL',
195199
'data' => ['bar' => 2]
200+
],[
201+
'spanId' => $spanData[2]['spanId'],
202+
'traceId' => $spanData[0]['traceId'],
203+
'parentId' => $spanData[0]['spanId'],
204+
'name' => 'my_third_span',
205+
'timestamp' => $spanData[2]['timestamp'],
206+
'duration' => $spanData[2]['duration'],
207+
'type' => 'EXIT',
208+
'data' => []
196209
]], $spanData);
197210
}
198211
}

test/Instana/OpenTracing/InstanaSpanTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@ public function verifyLocalReturnsSameInstanceAndHasCorrectTypeAndKind()
3838
$this->assertEquals(3, $exit->getKind());
3939
$this->assertEquals('local', $exit->getType());
4040
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function verifyExitTypeReturnsSameInstanceAndHasCorrectTypeAndKind()
46+
{
47+
$exit = InstanaSpanType::exitType();
48+
$this->assertSame($exit, InstanaSpanType::exitType());
49+
$this->assertEquals(2, $exit->getKind());
50+
$this->assertEquals('exit', $exit->getType());
51+
}
4152
}

test/Instana/OpenTracing/InstanaTcpSpanFlusherTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ public function startingActiveSpans()
148148

149149
$child = \OpenTracing\GlobalTracer::get()->startActiveSpan('my_second_span');
150150
$child->getSpan()->setTag('bar', 2);
151+
$child->close();
151152

153+
$child = \OpenTracing\GlobalTracer::get()->startActiveSpan('my_third_span');
154+
$child->getSpan()->setTag('span.kind', 'client');
152155
$child->close();
156+
153157
$parent->close();
154158

155159
\OpenTracing\GlobalTracer::get()->flush();
@@ -197,6 +201,24 @@ public function startingActiveSpans()
197201
]
198202
]
199203
]
204+
], [
205+
's' => $spanData[2]['s'],
206+
't' => $spanData[0]['t'],
207+
'p' => $spanData[0]['s'],
208+
'ta' => 'php',
209+
'n' => 'sdk',
210+
'ts' => $spanData[2]['ts'],
211+
'd' => $spanData[2]['d'],
212+
'k' => 2,
213+
'data' => [
214+
'sdk' => [
215+
'name' => 'my_third_span',
216+
'type' => 'exit',
217+
'custom' => [
218+
'tags' => []
219+
]
220+
]
221+
]
200222
]], $spanData);
201223
}
202224
}

0 commit comments

Comments
 (0)