Skip to content

Commit

Permalink
[Closes #28] Upgrade opentracing/opentracing-php to beta5 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgeorge authored Jun 14, 2018
1 parent a6c9433 commit 28b77c2
Show file tree
Hide file tree
Showing 42 changed files with 1,332 additions and 679 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ language: php
php:
- '7.0'
- '7.1'
- '7.2'
- nightly

install:
install:
- composer install

script:
script:
- vendor/bin/phpunit
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Jonah George
Copyright (c) 2018 Jonah George, José Carlos Chávez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md).
```sh
{
"require": {
"jonahgeorge/jaeger-client-php": "0.2.0"
"jonahgeorge/jaeger-client-php": "0.3.0"
}
}
```
Expand All @@ -30,7 +30,10 @@ use OpenTracing\GlobalTracer;

$config = new Config(
[
'sampler' => ['type' => 'const', 'param' => true],
'sampler' => [
'type' => 'const',
'param' => true,
],
'logging' => true,
],
'your-app-name'
Expand All @@ -39,8 +42,8 @@ $config->initializeTracer();

$tracer = GlobalTracer::get();

$span = $tracer->startSpan('TestSpan', []);
$span->finish();
$scope = $tracer->startActiveSpan('TestSpan', []);
$scope->close();

$tracer->flush();
```
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"require": {
"php": ">=7.0",
"packaged/thrift": "0.10.0",
"opentracing/opentracing" : "1.0.0-beta2",
"monolog/monolog": "^1.0",
"ext-gmp": "*"
"opentracing/opentracing" : "1.0.0-beta5",
"phlib/base_convert": "^1.0",
"psr/log": "1.0.2"
},
"provide": {
"opentracing/opentracing": "1.0.0-beta5"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
Expand Down
72 changes: 0 additions & 72 deletions src/Jaeger/Codec/B3Codec.php

This file was deleted.

4 changes: 3 additions & 1 deletion src/Jaeger/Codec/BinaryCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public function inject(SpanContext $spanContext, &$carrier)
throw new UnsupportedFormat('Binary encoding not implemented');
}

/** @return SpanContext|null */
/**
* @return SpanContext|null
*/
public function extract($carrier)
{
throw new UnsupportedFormat('Binary encoding not implemented');
Expand Down
4 changes: 3 additions & 1 deletion src/Jaeger/Codec/CodecInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface CodecInterface
{
public function inject(SpanContext $spanContext, &$carrier);

/** @return SpanContext|null */
/**
* @return SpanContext|null
*/
public function extract($carrier);
}
76 changes: 25 additions & 51 deletions src/Jaeger/Codec/TextCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace Jaeger\Codec;

use Exception;
use const Jaeger\BAGGAGE_HEADER_PREFIX;
use const Jaeger\DEBUG_ID_HEADER_KEY;
use Jaeger\SpanContext;

use const Jaeger\TRACE_ID_HEADER;
use const Jaeger\BAGGAGE_HEADER_PREFIX;
use const Jaeger\DEBUG_ID_HEADER_KEY;

use function Phlib\base_convert;

class TextCodec implements CodecInterface
{
Expand All @@ -16,8 +19,14 @@ class TextCodec implements CodecInterface
private $debugIdHeader;
private $prefixLength;

/**
* @param bool $urlEncoding
* @param string $traceIdHeader
* @param string $baggageHeaderPrefix
* @param string $debugIdHeader
*/
public function __construct(
bool $urlEncoding = False,
bool $urlEncoding = false,
string $traceIdHeader = TRACE_ID_HEADER,
string $baggageHeaderPrefix = BAGGAGE_HEADER_PREFIX,
string $debugIdHeader = DEBUG_ID_HEADER_KEY
Expand Down Expand Up @@ -52,7 +61,9 @@ public function inject(SpanContext $spanContext, &$carrier)
}
}

/** @return SpanContext|null */
/**
* @return SpanContext|null
*/
public function extract($carrier)
{
$traceId = null;
Expand Down Expand Up @@ -109,67 +120,30 @@ private function spanContextToString($traceId, $spanId, $parentId, $flags)
return sprintf('%x:%x:%x:%x', $traceId, $spanId, $parentId, $flags);
}

/**
* @return array
*/
private function spanContextFromString($value): array
{
$parts = explode(':', $value);

if (count($parts) != 4) {
throw new \Exception('Malformed tracer state string');
throw new Exception('Malformed tracer state string');
}

return [
$this->baseConvert($parts[0]),
$this->baseConvert($parts[1]),
$this->baseConvert($parts[2]),
base_convert($parts[0], 16, 10),
base_convert($parts[1], 16, 10),
base_convert($parts[2], 16, 10),
$parts[3],
];
}

/**
* Converts any string of any base to any other base without PHP native
* method base_convert's double and float limitations.
*
* @url https://github.com/credomane/php_baseconvert
*
* @param string $numstring
* @param int $frombase
* @param int $tobase
*
* @return string
* @param string $haystack
* @param string $needle
* @return bool
*/
private function baseConvert($numstring, $frombase = 16, $tobase = 10)
{
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$tostring = substr($chars, 0, $tobase);
$length = strlen($numstring);
$number = '';
$result = '';

for ($i = 0; $i < $length; $i++) {
$number[$i] = strpos($chars, $numstring{$i});
}

do {
$divide = 0;
$newlen = 0;

for ($i = 0; $i < $length; $i++) {
$divide = $divide * $frombase + $number[$i];

if ($divide >= $tobase) {
$number[$newlen++] = (int)($divide / $tobase);
$divide = $divide % $tobase;
} elseif ($newlen > 0) {
$number[$newlen++] = 0;
}
}
$length = $newlen;
$result = $tostring{$divide} . $result;
} while ($newlen != 0);

return $result;
}

private function startsWith(string $haystack, string $needle): bool
{
return substr($haystack, 0, strlen($needle)) == $needle;
Expand Down
48 changes: 0 additions & 48 deletions src/Jaeger/Codec/Utils.php

This file was deleted.

Loading

0 comments on commit 28b77c2

Please sign in to comment.